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 /ifuncs.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 'ifuncs.h')
-rw-r--r-- | ifuncs.h | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -19,8 +19,7 @@ static inline void alloc_xbuf(xbuf *xb, size_t sz) { - if (!(xb->buf = new_array(char, sz))) - out_of_memory("alloc_xbuf"); + xb->buf = new_array(char, sz); xb->size = sz; xb->len = xb->pos = 0; } @@ -29,8 +28,6 @@ static inline void realloc_xbuf(xbuf *xb, size_t sz) { char *bf = realloc_array(xb->buf, char, sz); - if (!bf) - out_of_memory("realloc_xbuf"); xb->buf = bf; xb->size = sz; } @@ -104,3 +101,11 @@ free_stat_x(stat_x *sx_p) } #endif } + +static inline char *my_strdup(const char *str, const char *file, int line) +{ + int len = strlen(str)+1; + char *buf = _my_alloc(do_malloc, len, 1, file, line); + memcpy(buf, str, len); + return buf; +} |