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. --- ifuncs.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'ifuncs.h') diff --git a/ifuncs.h b/ifuncs.h index 36ea51ad..7f9bde09 100644 --- a/ifuncs.h +++ b/ifuncs.h @@ -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; +} -- cgit v1.2.1