summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2020-11-09 11:50:09 -0800
committerJeremy Allison <jra@samba.org>2020-11-10 19:49:33 +0000
commit6598e00e129bc8b36d6d38345b67aba48b3eb26d (patch)
treef75487dd8168576a3b22699dfd505ec5b4e3ff8a
parent18fdfe8c10291e04b6a54499d74a6ee15652f5db (diff)
downloadsamba-6598e00e129bc8b36d6d38345b67aba48b3eb26d.tar.gz
lib: talloc: Remove the ALWAYS_REALLOC code paths.talloc-2.3.2
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 <jra@samba.org> Reviewed-by: Alexander Bokovoy <ab@samba.org>
-rw-r--r--lib/talloc/talloc.c69
-rw-r--r--lib/talloc/testsuite.c8
2 files changed, 1 insertions, 76 deletions
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 <valgrind.h>
#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
diff --git a/lib/talloc/testsuite.c b/lib/talloc/testsuite.c
index 6f23ad4e18a..282ebc6956d 100644
--- a/lib/talloc/testsuite.c
+++ b/lib/talloc/testsuite.c
@@ -1307,7 +1307,6 @@ static bool test_pool(void)
p4 = talloc_size(p3, 1000);
memset(p4, 0x11, talloc_get_size(p4));
-#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
p2_2 = talloc_realloc_size(pool, p2, 20+1);
torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed");
memset(p2, 0x11, talloc_get_size(p2));
@@ -1372,8 +1371,6 @@ static bool test_pool(void)
torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed");
memset(p3, 0x11, talloc_get_size(p3));
-#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
-
talloc_free(pool);
return true;
@@ -1408,7 +1405,6 @@ static bool test_pool_steal(void)
p1_2 = p1;
-#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
p1_2 = talloc_realloc_size(root, p1, 5 * 16);
torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed");
memset(p1_2, 0x11, talloc_get_size(p1_2));
@@ -1420,13 +1416,11 @@ static bool test_pool_steal(void)
p2_2 = talloc_realloc_size(root, p2, 3 * 16);
torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed");
memset(p2_2, 0x11, talloc_get_size(p2_2));
-#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
talloc_free(p1_2);
p2_2 = p2;
-#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
/* now we should reclaim the full pool */
p2_2 = talloc_realloc_size(root, p2, 8 * 16);
torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected");
@@ -1438,8 +1432,6 @@ static bool test_pool_steal(void)
torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected");
memset(p2_2, 0x11, talloc_get_size(p2_2));
-#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
-
talloc_free(p2_2);
talloc_free(root);