mirror of
https://github.com/json-c/json-c.git
synced 2026-03-23 06:59:06 +08:00
Merge pull request #781 from dddaniel/master
Fix memory leak with emtpy strings in json_object_set_string
This commit is contained in:
@@ -1323,11 +1323,18 @@ static int _json_object_set_string_len(json_object *jso, const char *s, size_t l
|
||||
// length as int, cap length at INT_MAX.
|
||||
return 0;
|
||||
|
||||
dstbuf = get_string_component_mutable(jso);
|
||||
curlen = JC_STRING(jso)->len;
|
||||
if (curlen < 0)
|
||||
curlen = -curlen;
|
||||
if (curlen < 0) {
|
||||
if (len == 0) {
|
||||
free(JC_STRING(jso)->c_string.pdata);
|
||||
JC_STRING(jso)->len = curlen = 0;
|
||||
} else {
|
||||
curlen = -curlen;
|
||||
}
|
||||
}
|
||||
|
||||
newlen = len;
|
||||
dstbuf = get_string_component_mutable(jso);
|
||||
|
||||
if ((ssize_t)len > curlen)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user