From 2e0cac8e3eb021aa8f5cad4ce8b72f98036af639 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 23 Apr 2005 18:07:01 +0000 Subject: r6445: Make us survive the PARANOID_MALLOC_CHECKER. Should we enable that for --enable-developer=yes? Volker (This used to be commit 61d40ac60dd9c8c9bbcf92e4fc57fe1d706bc721) --- source3/lib/util.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'source3/lib/util.c') diff --git a/source3/lib/util.c b/source3/lib/util.c index 52cf15da1e..77d4e6d2a6 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -984,18 +984,22 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size, void *element, void **array, uint32 *num_elements, ssize_t *array_size) { - if (*array_size == -1) + if (*array_size < 0) return; if (*array == NULL) { - if (*array_size == 0) + if (*array_size == 0) { *array_size = 128; + } + + if (*array_size >= MAX_ALLOC_SIZE/element_size) { + goto error; + } if (mem_ctx != NULL) - *array = talloc_array(mem_ctx, element_size, - *array_size); + *array = TALLOC(mem_ctx, element_size * (*array_size)); else - *array = malloc_array(element_size, *array_size); + *array = SMB_MALLOC(element_size * (*array_size)); if (*array == NULL) goto error; @@ -1004,13 +1008,16 @@ void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size, if (*num_elements == *array_size) { *array_size *= 2; + if (*array_size >= MAX_ALLOC_SIZE/element_size) { + goto error; + } + if (mem_ctx != NULL) - *array = talloc_realloc_array(mem_ctx, *array, - element_size, - *array_size); + *array = TALLOC_REALLOC(mem_ctx, *array, + element_size * (*array_size)); else - *array = realloc_array(*array, element_size, - *array_size); + *array = SMB_REALLOC(*array, + element_size * (*array_size)); if (*array == NULL) goto error; -- cgit