talloc: there is no ambiguity when freeing a ptr with a null parent
[samba.git] / lib / talloc / talloc.c
index d3b5565fe2c1e7241d6c5df2883c2a2e56508ad5..bd364ed51b8adbfd626e23b788ed775e50656c32 100644 (file)
@@ -1128,6 +1128,13 @@ _PUBLIC_ int _talloc_free(void *ptr, const char *location)
        if (unlikely(tc->refs != NULL)) {
                struct talloc_reference_handle *h;
 
+               if (talloc_parent(ptr) == null_context && tc->refs->next == NULL) {
+                       /* in this case we do know which parent should
+                          get this pointer, as there is really only
+                          one parent */
+                       return talloc_unlink(null_context, ptr);
+               }
+
                talloc_log("ERROR: talloc_free with references at %s\n",
                           location);