lib: Fix a valgrind error
authorVolker Lendecke <vl@samba.org>
Wed, 9 Jul 2014 13:51:06 +0000 (13:51 +0000)
committerStefan Metzmacher <metze@samba.org>
Tue, 22 Jul 2014 13:32:39 +0000 (15:32 +0200)
See the comment inside

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/background.c

index a9fd04f6a4a328ee4b147eeb03dc3062f3ed8774..869f2ef4750986a56e132f5b3348286f1d75a6c6 100644 (file)
@@ -181,7 +181,18 @@ static void background_job_waited(struct tevent_req *subreq)
                if (written == -1) {
                        _exit(1);
                }
-               TALLOC_FREE(state->msg);
+
+               /*
+                * No TALLOC_FREE here, messaging_parent_dgm_cleanup_init for
+                * example calls background_job_send with "messaging_context"
+                * as talloc parent. Thus "state" will be freed with the
+                * following talloc_free will have removed "state" when it
+                * returns. TALLOC_FREE will then write a NULL into free'ed
+                * memory. talloc_free() is required although we immediately
+                * exit, the messaging_context's destructor will want to clean
+                * up.
+                */
+               talloc_free(state->msg);
                _exit(0);
        }