cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit af5b4911de6e00306370460d978ac1654d3aeaec
parent 787d651e8131c6394c6ff844f108e1a53012949f
Author: Max Bruckner <max@maxbruckner.de>
Date:   Mon, 21 May 2018 22:00:07 +0200

Fix memory leak if realloc returns NULL

Thanks @AlfieDeng for reporting

Diffstat:
McJSON.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cJSON.c b/cJSON.c @@ -1113,10 +1113,10 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i if (hooks->reallocate != NULL) { printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); - buffer->buffer = NULL; if (printed == NULL) { goto fail; } + buffer->buffer = NULL; } else /* otherwise copy the JSON over to a new buffer */ {