summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Goldberg <rgoldber@redhat.com>2023-08-08 12:10:03 -0400
committerRyan Goldberg <rgoldber@redhat.com>2023-08-08 12:10:03 -0400
commit67c933483bb7cffd85ce37ac307dd793e8ffefcb (patch)
treed868722b8c387b72c9e39d4860bb1190f0a7ae71
parent9a04ca0f2287a0a40aef028e58e9b5a124fd5ac4 (diff)
PR29472: debuginfod: fixed memory leak from json array creationupstream/users/rgoldber/try-pr29472g
-rw-r--r--configure.ac2
-rw-r--r--debuginfod/debuginfod-client.c4
-rw-r--r--debuginfod/debuginfod.cxx2
3 files changed, 4 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index 409ccdbb..c785660a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -857,7 +857,7 @@ AS_IF([test "x$enable_debuginfod" != "xno"], [
PKG_CHECK_MODULES([oldlibmicrohttpd],[libmicrohttpd < 0.9.51],[old_libmicrohttpd=yes],[old_libmicrohttpd=no])
PKG_CHECK_MODULES([sqlite3],[sqlite3 >= 3.7.17],[],[enable_debuginfod=no])
PKG_CHECK_MODULES([libarchive],[libarchive >= 3.1.2],[],[enable_debuginfod=no])
- AC_CHECK_LIB(json-c, json_object_from_fd, [AC_SUBST(jsonc_LIBS, '-ljson-c')], [enable_libdebuginfod=no])
+ AC_CHECK_LIB(json-c, json_object_from_fd, [AC_SUBST(jsonc_LIBS, '-ljson-c')], [enable_debuginfod=no])
if test "x$enable_debuginfod" = "xno"; then
AC_MSG_ERROR([dependencies not found, use --disable-debuginfod to disable.])
fi
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index bd7a92c0..4235ab64 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -2149,10 +2149,11 @@ int debuginfod_find_metadata (debuginfod_client *client,
json_object *json_metadata = json_object_new_object();
json_bool json_metadata_complete = true;
json_object *json_metadata_arr = json_object_new_array();
- if(NULL == json_metadata || NULL == json_metadata_arr) {
+ if(NULL == json_metadata) {
rc = -ENOMEM;
goto out;
}
+ json_object_object_add(json_metadata, "results", json_metadata_arr != NULL ? json_metadata_arr : json_object_new_array_ext(0) /* Empty array */);
if(NULL == value || NULL == key){
rc = -EINVAL;
@@ -2415,7 +2416,6 @@ int debuginfod_find_metadata (debuginfod_client *client,
/* Plop the complete json_metadata object into the cache. */
- json_object_object_add(json_metadata, "results", json_metadata_arr);
json_object_object_add(json_metadata, "complete", json_object_new_boolean(json_metadata_complete));
const char* json_string = json_object_to_json_string_ext(json_metadata, JSON_C_TO_STRING_PRETTY);
if (json_string == NULL)
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index e006f09c..a611f3ca 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -2751,6 +2751,7 @@ handle_metadata (MHD_Connection* conn,
defer_dtor<json_object*,int> metadata_d(metadata, json_object_put);
json_object *metadata_arr = json_object_new_array();
if (!metadata_arr) throw libc_exception(ENOMEM, "json allocation");
+ json_object_object_add(metadata, "results", metadata_arr);
// consume all the rows
struct timespec ts_start;
clock_gettime (CLOCK_MONOTONIC, &ts_start);
@@ -2861,7 +2862,6 @@ handle_metadata (MHD_Connection* conn,
<< " total=" << num_total_results
<< endl;
- json_object_object_add(metadata, "results", metadata_arr);
json_object_object_add(metadata, "complete", json_object_new_boolean(metadata_complete));
const char* metadata_str = json_object_to_json_string(metadata);
if (!metadata_str)