Pārlūkot izejas kodu

Fix memory leak if realloc returns NULL

Thanks @AlfieDeng for reporting
Max Bruckner 7 gadi atpakaļ
vecāks
revīzija
af5b4911de
1 mainītis faili ar 1 papildinājumiem un 1 dzēšanām
  1. 1 1
      cJSON.c

+ 1 - 1
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 */
     {