diff options
author | Wayne Davison <wayne@opencoder.net> | 2020-06-25 19:59:19 -0700 |
---|---|---|
committer | Wayne Davison <wayne@opencoder.net> | 2020-06-25 20:54:21 -0700 |
commit | 11eb67eec9b4d990ae4df680cf7db77dad1b8630 (patch) | |
tree | 977f60274b7784ad12854bbe575503bae46c3e6c /rsync.h | |
parent | 39a083b16b6d229f32078569ea8bd2c4bb29a44b (diff) | |
download | rsync-11eb67eec9b4d990ae4df680cf7db77dad1b8630.tar.gz |
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.
Diffstat (limited to 'rsync.h')
-rw-r--r-- | rsync.h | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -1262,12 +1262,18 @@ extern int errno; /* handler for null strings in printf format */ #define NS(s) ((s)?(s):"<NULL>") +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 *, ...) |