In _talloc_steal_internal(), correctly decrement the memory limit in the source,...
authorJeremy Allison <jra@samba.org>
Tue, 27 Aug 2013 19:57:43 +0000 (12:57 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 27 Aug 2013 22:44:19 +0000 (15:44 -0700)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Simo Sorce <idra@samba.org>
lib/talloc/talloc.c

index 74eca3f5e65a63194c247aa088b9ec20e24c2114..54f3c0a56d3a1a901c42724f94264042ac0dbdf5 100644 (file)
@@ -976,11 +976,8 @@ static void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
 
                ctx_size = _talloc_total_limit_size(ptr, NULL, NULL);
 
-               if (!talloc_memlimit_update(tc->limit->upper, ctx_size, 0)) {
-                       talloc_abort("cur_size memlimit counter not correct!");
-                       errno = EINVAL;
-                       return NULL;
-               }
+               /* Decrement the memory limit from the source .. */
+               talloc_memlimit_shrink(tc->limit->upper, ctx_size);
 
                if (tc->limit->parent == tc) {
                        tc->limit->upper = NULL;
@@ -1028,13 +1025,9 @@ static void *_talloc_steal_internal(const void *new_ctx, const void *ptr)
        if (tc->limit || new_tc->limit) {
                ctx_size = _talloc_total_limit_size(ptr, tc->limit,
                                                    new_tc->limit);
-       }
-
-       if (new_tc->limit) {
-               struct talloc_memlimit *l;
-
-               for (l = new_tc->limit; l != NULL; l = l->upper) {
-                       l->cur_size += ctx_size;
+               /* .. and increment it in the destination. */
+               if (new_tc->limit) {
+                       talloc_memlimit_grow(new_tc->limit, ctx_size);
                }
        }