Skip to content

Commit

Permalink
Fix #105, double free when parse_string fails
Browse files Browse the repository at this point in the history
This fixes a double free that happens when calling cJSON_Delete on an
item that has been used by parse_string and it failed parsing the
string.

The double free happens, because parse_string frees an alias of
item->valuestring, but doesn't set item->valuestring to NULL.
  • Loading branch information
FSMaxB committed Feb 15, 2017
1 parent c3bd446 commit 94117a5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ static const unsigned char *parse_string(cJSON *item, const unsigned char *str,
{
goto fail;
}
item->valuestring = (char*)out; /* assign here so out will be deleted during cJSON_Delete() later */
item->type = cJSON_String;

ptr = str + 1;
Expand Down Expand Up @@ -608,6 +607,8 @@ static const unsigned char *parse_string(cJSON *item, const unsigned char *str,
ptr++;
}

item->valuestring = (char*)out;

return ptr;

fail:
Expand Down

0 comments on commit 94117a5

Please sign in to comment.