]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util: add atexit handling and complain about dangling frames.
authorStefan Metzmacher <metze@samba.org>
Mon, 12 May 2025 18:50:10 +0000 (20:50 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 19 May 2025 09:11:29 +0000 (09:11 +0000)
We don't panic yet as pylibsmb.c would trigger that...
This will be fixed in the next commits.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/talloc_stack.c

index d541ed01603fbf334496303f000e34438f8e51b6..25ed38633ff8669b045638910124d4c0e30f78de 100644 (file)
@@ -51,10 +51,47 @@ struct talloc_stackframe {
 
 static struct talloc_stackframe *global_ts;
 
+static void talloc_stackframe_destructor(void *ptr)
+{
+       struct talloc_stackframe *ts =
+               (struct talloc_stackframe *)ptr;
+       int i;
+
+       for (i = 0; i < ts->talloc_stacksize; i++) {
+               int idx = ts->talloc_stacksize - (i + 1);
+               DEBUG(0, ("Dangling frame[%d] %s\n",
+                         idx, talloc_get_name(ts->talloc_stack[idx])));
+       }
+       if (ts->talloc_stacksize > 0) {
+#if 0 /* TODO ifdef DEVELOPER */
+               smb_panic("Dangling frames.");
+#endif
+       }
+
+       free(ts);
+}
+
+static void talloc_stackframe_atexit(void)
+{
+       talloc_stackframe_destructor(global_ts);
+}
+
+static void talloc_stackframe_init(void)
+{
+       static bool done;
+
+       if (!done) {
+               atexit(talloc_stackframe_atexit);
+               done = true;
+       }
+}
+
 static struct talloc_stackframe *talloc_stackframe_get_existing(void)
 {
        struct talloc_stackframe *ts = NULL;
 
+       talloc_stackframe_init();
+
        ts = global_ts;
 
        return ts;