mirror of
https://github.com/DaveGamble/cJSON.git
synced 2024-12-26 21:04:24 +08:00
Fix memory leak if realloc returns NULL
Thanks @AlfieDeng for reporting
This commit is contained in:
parent
787d651e81
commit
af5b4911de
2
cJSON.c
2
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 */
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user