diff --git a/include/c/defs.h b/include/c/defs.h index 5332d42a1..c0eb6e570 100644 --- a/include/c/defs.h +++ b/include/c/defs.h @@ -97,3 +97,12 @@ void* rut = c3_malloc(s); \ memset(rut, 0, s); \ rut;}) + +/* c3_realloc(): asserting realloc + */ +#define c3_realloc(a, b) ({ \ + void* rut = realloc(a, b); \ + if ( 0 == rut ) { \ + c3_assert(!"memory lost"); \ + } \ + rut;}) diff --git a/vere/dawn.c b/vere/dawn.c index e18676372..2611b28d4 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -14,12 +14,7 @@ static size_t _dawn_curl_alloc(void* dat_v, size_t uni_t, size_t mem_t, uv_buf_t* buf_u) { size_t siz_t = uni_t * mem_t; - buf_u->base = realloc(buf_u->base, 1 + siz_t + buf_u->len); - - if ( 0 == buf_u->base ) { - fprintf(stderr, "out of memory\n"); - u3_lo_bail(); - } + buf_u->base = c3_realloc(buf_u->base, 1 + siz_t + buf_u->len); memcpy(buf_u->base + buf_u->len, dat_v, siz_t); buf_u->len += siz_t; diff --git a/vere/http.c b/vere/http.c index 01ffc9b50..e0ee698ca 100644 --- a/vere/http.c +++ b/vere/http.c @@ -2687,9 +2687,7 @@ _proxy_peek_read_cb(uv_stream_t* don_u, } else { c3_w len_w = siz_w + con_u->buf_u.len; - // XX c3_realloc - void* ptr_v = realloc(con_u->buf_u.base, len_w); - c3_assert( 0 != ptr_v ); + void* ptr_v = c3_realloc(con_u->buf_u.base, len_w); memcpy(ptr_v + con_u->buf_u.len, buf_u->base, siz_w); con_u->buf_u = uv_buf_init(ptr_v, len_w);