Don't use the autofree context for the globals. This causes child smbd's forked
authorJeremy Allison <jra@samba.org>
Thu, 10 Jun 2010 20:17:35 +0000 (13:17 -0700)
committerJeremy Allison <jra@samba.org>
Thu, 10 Jun 2010 20:17:35 +0000 (13:17 -0700)
by modules to crash due to destructors being called (found when using the vfs_aio_fork
module with smb2).

Jeremy.

source3/smbd/globals.c
source3/smbd/server.c
source3/smbd/server_exit.c

index 30a306efbbb6f690279cd710ad43539e8b5a6c3a..3150b9f67fd68dec768631de6169550ae924b66c 100644 (file)
@@ -125,7 +125,12 @@ struct smbd_server_connection *smbd_server_conn = NULL;
 struct messaging_context *smbd_messaging_context(void)
 {
        if (smbd_msg_ctx == NULL) {
-               smbd_msg_ctx = messaging_init(talloc_autofree_context(),
+               /*
+                * Note we MUST use the NULL context here, not the
+                * autofree context, to avoid side effects in forked
+                * children exiting.
+                */
+               smbd_msg_ctx = messaging_init(NULL,
                                              procid_self(),
                                              smbd_event_context());
        }
@@ -138,7 +143,12 @@ struct messaging_context *smbd_messaging_context(void)
 struct memcache *smbd_memcache(void)
 {
        if (!smbd_memcache_ctx) {
-               smbd_memcache_ctx = memcache_init(talloc_autofree_context(),
+               /*
+                * Note we MUST use the NULL context here, not the
+                * autofree context, to avoid side effects in forked
+                * children exiting.
+                */
+               smbd_memcache_ctx = memcache_init(NULL,
                                                  lp_max_stat_cache_size()*1024);
        }
        if (!smbd_memcache_ctx) {
index 184b613810d939f349a5d43c0b12316433eafbb9..a7297d68630f4f0bcc36f56dc8a973de5223cd8c 100644 (file)
@@ -50,7 +50,12 @@ int get_client_fd(void)
 struct event_context *smbd_event_context(void)
 {
        if (!smbd_event_ctx) {
-               smbd_event_ctx = event_context_init(talloc_autofree_context());
+               /*
+                * Note we MUST use the NULL context here, not the
+                * autofree context, to avoid side effects in forked
+                * children exiting.
+                */
+               smbd_event_ctx = event_context_init(NULL);
        }
        if (!smbd_event_ctx) {
                smb_panic("Could not init smbd event context");
index 868cd67b4fcdce7c16ef85cce13d4fa89de53c9e..3e0da3e1cf71d1bdd5fc860d27d4e17eded2a9d9 100644 (file)
@@ -121,6 +121,7 @@ static void exit_server_common(enum server_exit_reason how,
        TALLOC_FREE(smbd_server_conn);
        TALLOC_FREE(smbd_msg_ctx);
        TALLOC_FREE(smbd_event_ctx);
+       TALLOC_FREE(smbd_memcache_ctx);
 
        if (how != SERVER_EXIT_NORMAL) {
                int oldlevel = DEBUGLEVEL;