Add extra argument free_on_fail to realloc_array() in Samba 4, as used by Samba 3.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 18 Oct 2008 12:12:56 +0000 (14:12 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 18 Oct 2008 12:12:56 +0000 (14:12 +0200)
lib/util/memory.h
lib/util/util.c
lib/util/util.h

index 29dd75060f96bb156ab2de8979c7f4b26ea463e4..de01492aa255f7e8678d9f4c291a3420af8e4ae9 100644 (file)
 /**
  * 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 
index 5fc785d642db96da2c8b357c853266efe083c04e..4c5ae973a13ec9eb0fa8ac9e41424c4c567a2501 100644 (file)
@@ -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)
index 02309d118de44b51f895dab09abf39a3b334c9a6..e4a5a0c662912ffc4035668cfab72a8209094123 100644 (file)
@@ -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  */