From e0bd6b2019932538eaf1c83939117e066dcc55ce Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 17 Apr 2019 14:39:47 +0200 Subject: [PATCH] another fix --- client/tinycbor/open_memstream.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/client/tinycbor/open_memstream.c b/client/tinycbor/open_memstream.c index 0085641f9..043079143 100644 --- a/client/tinycbor/open_memstream.c +++ b/client/tinycbor/open_memstream.c @@ -65,11 +65,15 @@ static RetType write_to_buffer(void *cookie, const char *data, LenType len) { if (newsize >= b->alloc) { // NB! one extra byte is needed to avoid buffer overflow at close_buffer // make room size_t newalloc = newsize + newsize / 2 + 1; // give 50% more room - ptr = realloc(ptr, newalloc); - if (ptr == NULL) { + + char *tmp = realloc(ptr, newalloc); + if ( tmp == NULL ) { free(ptr); return -1; - ) + } else { + ptr = tmp; + } + b->alloc = newalloc; *b->ptr = ptr; }