Change __talloc() to only call talloc_memlimit_check()/talloc_memlimit_grow() on...
authorJeremy Allison <jra@samba.org>
Tue, 27 Aug 2013 19:49:00 +0000 (12:49 -0700)
committerStefan Metzmacher <metze@samba.org>
Tue, 10 Mar 2015 09:55:36 +0000 (10:55 +0100)
Don't check the memlimit if the allocation was successful from a pool. We already
checked the memory limit when we created the pool.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Simo Sorce <idra@samba.org>
(cherry picked from commit a4ebbe73b4b8dcab4d344e693ad9796ec8997f87)

lib/talloc/talloc.c

index 1e25dfde4e1e998872276ef3acb1eec80606cb25..cee7d23ef7cfb382d03c23df42fab0f0248aa7b0 100644 (file)
@@ -586,27 +586,24 @@ static inline void *__talloc(const void *context, size_t size)
                        limit = ptc->limit;
                }
 
-               if (!talloc_memlimit_check(limit, (TC_HDR_SIZE+size))) {
-                       errno = ENOMEM;
-                       return NULL;
-               }
-
                tc = talloc_alloc_pool(ptc, TC_HDR_SIZE+size);
        }
 
        if (tc == NULL) {
+               /*
+                * Only do the memlimit check/update on actual allocation.
+                */
+               if (!talloc_memlimit_check(limit, TC_HDR_SIZE + size)) {
+                       errno = ENOMEM;
+                       return NULL;
+               }
+
                tc = (struct talloc_chunk *)malloc(TC_HDR_SIZE+size);
                if (unlikely(tc == NULL)) return NULL;
                tc->flags = TALLOC_MAGIC;
                tc->pool  = NULL;
-       }
 
-       if (limit != NULL) {
-               struct talloc_memlimit *l;
-
-               for (l = limit; l != NULL; l = l->upper) {
-                       l->cur_size += TC_HDR_SIZE+size;
-               }
+               talloc_memlimit_grow(limit, TC_HDR_SIZE + size);
        }
 
        tc->limit = limit;