diff options
author | Jeremy Allison <jra@samba.org> | 2013-08-27 12:49:00 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2013-08-27 15:44:19 -0700 |
commit | a4ebbe73b4b8dcab4d344e693ad9796ec8997f87 (patch) | |
tree | 27756019ee0e9751b09f4c0091f7bbd67547d262 | |
parent | 4159a78ed7eda340758e22286f16186987a20f2f (diff) | |
download | samba-a4ebbe73b4b8dcab4d344e693ad9796ec8997f87.tar.gz samba-a4ebbe73b4b8dcab4d344e693ad9796ec8997f87.tar.bz2 samba-a4ebbe73b4b8dcab4d344e693ad9796ec8997f87.zip |
Change __talloc() to only call talloc_memlimit_check()/talloc_memlimit_grow() on actual malloc allocation.
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>
-rw-r--r-- | lib/talloc/talloc.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index 1e25dfde4e..cee7d23ef7 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -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; |