Use json_object_set_new

The non-set case should only be used when a copy of an existing object is
needed. This fixes a memory leak in Cache::do_get_info.
This commit is contained in:
Markus Mäkelä 2020-03-09 07:51:08 +02:00
parent 6f45545e09
commit f7d502d1e1
No known key found for this signature in database
GPG Key ID: 5CE746D557ACC499
5 changed files with 7 additions and 13 deletions

View File

@ -202,7 +202,7 @@ json_t* Cache::do_get_info(uint32_t what) const
// failure.
}
json_object_set(pInfo, "rules", pArray);
json_object_set_new(pInfo, "rules", pArray);
}
}
}

View File

@ -112,8 +112,7 @@ json_t* CachePT::get_info(uint32_t what) const
if (pThreadInfo)
{
json_object_set(pInfo, key, pThreadInfo);
json_decref(pThreadInfo);
json_object_set_new(pInfo, key, pThreadInfo);
}
}
}

View File

@ -90,8 +90,7 @@ json_t* CacheSimple::do_get_info(uint32_t what) const
if (CACHE_RESULT_IS_OK(result))
{
json_object_set(pInfo, "storage", pStorageInfo);
json_decref(pStorageInfo);
json_object_set_new(pInfo, "storage", pStorageInfo);
}
}

View File

@ -54,8 +54,7 @@ cache_result_t LRUStorage::do_get_info(uint32_t what,
{
m_stats.fill(pLru);
json_object_set(*ppInfo, "lru", pLru);
json_decref(pLru);
json_object_set_new(*ppInfo, "lru", pLru);
}
json_t* pStorage_info;
@ -64,8 +63,7 @@ cache_result_t LRUStorage::do_get_info(uint32_t what,
if (CACHE_RESULT_IS_OK(result))
{
json_object_set(*ppInfo, "real_storage", pStorage_info);
json_decref(pStorage_info);
json_object_set_new(*ppInfo, "real_storage", pStorage_info);
}
}
@ -596,8 +594,7 @@ static void set_integer(json_t* pObject, const char* zName, size_t value)
if (pValue)
{
json_object_set(pObject, zName, pValue);
json_decref(pValue);
json_object_set_new(pObject, zName, pValue);
}
}

View File

@ -282,8 +282,7 @@ static void set_integer(json_t* pObject, const char* zName, size_t value)
if (pValue)
{
json_object_set(pObject, zName, pValue);
json_decref(pValue);
json_object_set_new(pObject, zName, pValue);
}
}