diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/memory.h | 8 | ||||
-rw-r--r-- | lib/util/util.c | 6 | ||||
-rw-r--r-- | lib/util/util.h | 2 |
3 files changed, 5 insertions, 11 deletions
diff --git a/lib/util/memory.h b/lib/util/memory.h index 29dd75060f..de01492aa2 100644 --- a/lib/util/memory.h +++ b/lib/util/memory.h @@ -40,20 +40,12 @@ /** * Allocate an array of elements of one data type. Does type-checking. */ -#if _SAMBA_BUILD_ == 3 #define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count, false) -#else -#define malloc_array_p(type, count) (type *)realloc_array(NULL, sizeof(type), count) -#endif /** * Resize an array of elements of one data type. Does type-checking. */ -#if _SAMBA_BUILD_ == 3 #define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count, false) -#else -#define realloc_p(p, type, count) (type *)realloc_array(p, sizeof(type), count) -#endif /** * zero a structure diff --git a/lib/util/util.c b/lib/util/util.c index 5fc785d642..4c5ae973a1 100644 --- a/lib/util/util.c +++ b/lib/util/util.c @@ -569,11 +569,13 @@ _PUBLIC_ bool all_zero(const uint8_t *ptr, size_t size) /** realloc an array, checking for integer overflow in the array size */ -_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count) +_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count, bool free_on_fail) { #define MAX_MALLOC_SIZE 0x7fffffff if (count == 0 || count >= MAX_MALLOC_SIZE/el_size) { + if (free_on_fail) + SAFE_FREE(ptr); return NULL; } if (!ptr) { @@ -588,7 +590,7 @@ _PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count) void *malloc_array(size_t el_size, unsigned int count) { - return realloc_array(NULL, el_size, count); + return realloc_array(NULL, el_size, count, false); } _PUBLIC_ void *talloc_check_name_abort(const void *ptr, const char *name) diff --git a/lib/util/util.h b/lib/util/util.h index 02309d118d..e4a5a0c662 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -634,7 +634,7 @@ _PUBLIC_ bool all_zero(const uint8_t *ptr, size_t size); /** realloc an array, checking for integer overflow in the array size */ -_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count); +_PUBLIC_ void *realloc_array(void *ptr, size_t el_size, unsigned count, bool free_on_fail); /* The following definitions come from lib/util/fsusage.c */ |