From 11eb67eec9b4d990ae4df680cf7db77dad1b8630 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Thu, 25 Jun 2020 19:59:19 -0700 Subject: Some memory allocation improvements - All the memory-allocation macros now auto-check for failure and exit with a failure message that incudes the caller's file and lineno info. This includes strdup(). - Added the `--max-alloc=SIZE` option to be able to override the memory allocator's sanity-check limit. It defaults to 1G (as before). Fixes bugzilla bug 12769. --- rsync.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'rsync.h') diff --git a/rsync.h b/rsync.h index a645f201..ef2668d1 100644 --- a/rsync.h +++ b/rsync.h @@ -1262,12 +1262,18 @@ extern int errno; /* handler for null strings in printf format */ #define NS(s) ((s)?(s):"") +extern char *do_malloc; + /* Convenient wrappers for malloc and realloc. Use them. */ -#define new(type) ((type*)malloc(sizeof (type))) -#define new0(type) ((type*)calloc(1, sizeof (type))) -#define new_array(type, num) ((type*)_new_array((num), sizeof (type), 0)) -#define new_array0(type, num) ((type*)_new_array((num), sizeof (type), 1)) -#define realloc_array(ptr, type, num) ((type*)_realloc_array((ptr), (num), sizeof (type))) +#define new(type) ((type*)_my_alloc(do_malloc, 1, sizeof (type), __FILE__, __LINE__)) +#define new0(type) ((type*)_my_alloc(NULL, 1, sizeof (type), __FILE__, __LINE__)) +#define realloc_buf(ptr, num) _my_alloc((ptr), (num), 1, __FILE__, __LINE__) + +#define new_array(type, num) ((type*)_my_alloc(do_malloc, (num), sizeof (type), __FILE__, __LINE__)) +#define new_array0(type, num) ((type*)_my_alloc(NULL, (num), sizeof (type), __FILE__, __LINE__)) +#define realloc_array(ptr, type, num) ((type*)_my_alloc((ptr), (num), sizeof (type), __FILE__, __LINE__)) + +#define strdup(s) my_strdup(s, __FILE__, __LINE__) /* use magic gcc attributes to catch format errors */ void rprintf(enum logcode , const char *, ...) -- cgit v1.2.1