PREVIEW: alter ldb_msg_canonicalize to allocate memory in NULL
authorKamen Mazdrashki <kamenim@samba.org>
Sun, 4 Jul 2010 19:11:53 +0000 (22:11 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Sun, 4 Jul 2010 19:11:53 +0000 (22:11 +0300)
Returned message will be allocated into NULL memory
context. It is strongly advised for callers to steal
the message returned into a local memory context.
Allocating ldb_msg into NULL context should appear
as memory leak (kind of) and thus make it easier to identify
places where ldb_msg_canonicalize() is misused

source4/lib/ldb/common/ldb_msg.c

index 4d0149af8f45d77aac36fcfeb817b0ea399e3817..29bdabcdd99bde0f47230ec5161c4ae55c704f8c 100644 (file)
@@ -543,6 +543,13 @@ failed:
 
 /*
   canonicalise a message, merging elements of the same name
+
+  NOTE: Returned message will be allocated into NULL memory
+       context. It is strongly advised for callers to steal
+       the message returned into a local memory context.
+       Allocating ldb_msg into NULL context should appear
+       as memory leak (kind of) and thus make it easier to identify
+       places where ldb_msg_canonicalize() is misused
 */
 struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb, 
                                         const struct ldb_message *msg)
@@ -550,8 +557,10 @@ struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb,
        unsigned int i;
        struct ldb_message *msg2;
 
-       msg2 = ldb_msg_copy(ldb, msg);
-       if (msg2 == NULL) return NULL;
+       msg2 = ldb_msg_copy(NULL, msg);
+       if (msg2 == NULL) {
+               return NULL;
+       }
 
        ldb_msg_sort_elements(msg2);