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:
parent
6f45545e09
commit
f7d502d1e1
2
server/modules/filter/cache/cache.cc
vendored
2
server/modules/filter/cache/cache.cc
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
server/modules/filter/cache/cachept.cc
vendored
3
server/modules/filter/cache/cachept.cc
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
3
server/modules/filter/cache/cachesimple.cc
vendored
3
server/modules/filter/cache/cachesimple.cc
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
9
server/modules/filter/cache/lrustorage.cc
vendored
9
server/modules/filter/cache/lrustorage.cc
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user