mirror of
https://github.com/json-c/json-c.git
synced 2026-04-09 07:19: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.
|
// length as int, cap length at INT_MAX.
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
dstbuf = get_string_component_mutable(jso);
|
|
||||||
curlen = JC_STRING(jso)->len;
|
curlen = JC_STRING(jso)->len;
|
||||||
if (curlen < 0)
|
if (curlen < 0) {
|
||||||
curlen = -curlen;
|
if (len == 0) {
|
||||||
|
free(JC_STRING(jso)->c_string.pdata);
|
||||||
|
JC_STRING(jso)->len = curlen = 0;
|
||||||
|
} else {
|
||||||
|
curlen = -curlen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
newlen = len;
|
newlen = len;
|
||||||
|
dstbuf = get_string_component_mutable(jso);
|
||||||
|
|
||||||
if ((ssize_t)len > curlen)
|
if ((ssize_t)len > curlen)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user