From e84a97c23e019d9e4aef73a0a528eb2686ad0b4f Mon Sep 17 00:00:00 2001 From: Mikhail Khachayants Date: Mon, 16 Dec 2024 23:42:11 +0200 Subject: [PATCH] fix: memory leak in clib_package_new Direct leak of 32 byte(s) in 1 object(s) allocated from: 0 malloc 1 json_object_init clib/deps/parson/parson.c:291:42 2 json_value_init_object clib/deps/parson/parson.c:1077:31 3 parse_object_value clib/deps/parson/parson.c:580:32 4 parse_value clib/deps/parson/parson.c:561:20 5 parse_object_value clib/deps/parson/parson.c:600:21 6 parse_value clib/deps/parson/parson.c:561:20 7 json_parse_string clib/deps/parson/parson.c:910:12 8 clib_package_new clib/src/common/clib-package.c:468:16 9 clib_package_load_from_manifest clib/src/common/clib-package.c:259:9 --- src/common/clib-package.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/clib-package.c b/src/common/clib-package.c index 136754e..0870117 100644 --- a/src/common/clib-package.c +++ b/src/common/clib-package.c @@ -513,6 +513,8 @@ clib_package_t *clib_package_new(const char *json, int verbose) { for (unsigned int i = 0; i < json_array_get_count(flags); i++) { char *flag = json_array_get_string_safe(flags, i); if (flag) { + char *old_flags = pkg->flags; + if (!pkg->flags) { pkg->flags = ""; } @@ -521,6 +523,7 @@ clib_package_t *clib_package_new(const char *json, int verbose) { goto cleanup; } + free(old_flags); free(flag); } }