From 6598e00e129bc8b36d6d38345b67aba48b3eb26d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Nov 2020 11:50:09 -0800 Subject: lib: talloc: Remove the ALWAYS_REALLOC code paths. This is now never set, and also never tested, and only makes the talloc code more complicated. Once this is gone we can start looking at the memlimit stuff. Signed-off-by: Jeremy Allison Reviewed-by: Alexander Bokovoy --- lib/talloc/talloc.c | 69 +---------------------------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) (limited to 'lib/talloc/talloc.c') diff --git a/lib/talloc/talloc.c b/lib/talloc/talloc.c index ef49429307a..29da190880a 100644 --- a/lib/talloc/talloc.c +++ b/lib/talloc/talloc.c @@ -54,11 +54,6 @@ #include #endif -/* use this to force every realloc to change the pointer, to stress test - code that might not cope */ -#define ALWAYS_REALLOC 0 - - #define MAX_TALLOC_SIZE 0x10000000 #define TALLOC_FLAG_FREE 0x01 @@ -1844,7 +1839,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons pool_hdr = tc->pool; } -#if (ALWAYS_REALLOC == 0) /* don't shrink if we have less than 1k to gain */ if (size < tc->size && tc->limit == NULL) { if (pool_hdr) { @@ -1878,7 +1872,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons */ return ptr; } -#endif /* * by resetting magic we catch users of the old memory @@ -1897,66 +1890,6 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons */ _talloc_chunk_set_free(tc, NULL); -#if (ALWAYS_REALLOC != 0) - if (pool_hdr) { - new_ptr = tc_alloc_pool(tc, size + TC_HDR_SIZE, 0); - if (new_ptr == NULL) { - /* - * Couldn't allocate from pool (pool size - * counts as already allocated for memlimit - * purposes). We must check memory limit - * before any real malloc. - */ - if (tc->limit) { - /* - * Note we're doing an extra malloc, - * on top of the pool size, so account - * for size only, not the difference - * between old and new size. - */ - if (!talloc_memlimit_check(tc->limit, size)) { - _talloc_chunk_set_not_free(tc); - errno = ENOMEM; - return NULL; - } - } - new_ptr = malloc(TC_HDR_SIZE+size); - malloced = true; - new_size = size; - } - - if (new_ptr) { - memcpy(new_ptr, tc, MIN(tc->size,size) + TC_HDR_SIZE); - TC_INVALIDATE_FULL_CHUNK(tc); - /* - * Only decrement the object count in the pool once - * we know we're returning a valid new_ptr. - */ - pool_hdr->object_count--; - } - } else { - /* We're doing malloc then free here, so record the difference. */ - old_size = tc->size; - new_size = size; - /* - * We must check memory limit - * before any real malloc. - */ - if (tc->limit && (size > old_size)) { - if (!talloc_memlimit_check(tc->limit, - (size - old_size))) { - _talloc_chunk_set_not_free(tc); - errno = ENOMEM; - return NULL; - } - } - new_ptr = malloc(size + TC_HDR_SIZE); - if (new_ptr) { - memcpy(new_ptr, tc, MIN(tc->size, size) + TC_HDR_SIZE); - free(tc); - } - } -#else if (pool_hdr) { struct talloc_chunk *pool_tc; void *next_tc = tc_next_chunk(tc); @@ -2102,7 +2035,7 @@ _PUBLIC_ void *_talloc_realloc(const void *context, void *ptr, size_t size, cons new_ptr = realloc(tc, size + TC_HDR_SIZE); } got_new_ptr: -#endif + if (unlikely(!new_ptr)) { /* * Ok, this is a strange spot. We have to put back -- cgit v1.2.1