]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Patch some memory leaks
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Fri, 17 Nov 2023 22:04:28 +0000 (16:04 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Sat, 18 Nov 2023 01:02:24 +0000 (19:02 -0600)
src/cache/local_cache.c
src/config.c
src/json_util.c
src/rsync/rsync.c

index f6116b9df13e4acb93d7ed14ca48851915be23eb..9d0a619fc75932d9cb691217d67daf0b2c3f3b4f 100644 (file)
@@ -325,10 +325,8 @@ node2json(struct cache_node *node)
 
        if (node->children != NULL) {
                children = json_array();
-               if (children == NULL) {
-                       pr_op_err("json array allocation failure.");
-                       return NULL;
-               }
+               if (children == NULL)
+                       enomem_panic();
 
                if (json_object_set_new(json, TAGNAME_CHILDREN, children)) {
                        pr_op_err("Cannot push children array into json node; unknown cause.");
@@ -339,7 +337,7 @@ node2json(struct cache_node *node)
                        jchild = node2json(child);
                        if (jchild == NULL)
                                goto cancel; /* Error msg already printed */
-                       if (json_array_append(children, jchild)) {
+                       if (json_array_append_new(children, jchild)) {
                                pr_op_err("Cannot push child into json node; unknown cause.");
                                goto cancel;
                        }
@@ -363,7 +361,7 @@ append_node(json_t *root, struct cache_node *node, char const *name)
        child = node2json(node);
        if (child == NULL)
                return -1;
-       if (json_array_append(root, child)) {
+       if (json_array_append_new(root, child)) {
                pr_op_err("Cannot push %s json node into json root; unknown cause.",
                    name);
                return -1;
@@ -403,13 +401,13 @@ write_metadata_json(struct rpki_cache *cache)
                return;
 
        if (get_metadata_json_filename(cache->tal, &filename) != 0)
-               return;
+               goto end;
 
        if (json_dump_file(json, filename, JSON_COMPACT))
                pr_op_err("Unable to write metadata.json; unknown cause.");
 
        free(filename);
-       json_decref(json);
+end:   json_decref(json);
 }
 
 struct rpki_cache *
index 0ce330ad01935f11c967c8a070a95fc3307c672b..c0ca15b739a1f20f20f304202ca62eb575a8765a 100644 (file)
@@ -522,7 +522,7 @@ static const struct option_field options[] = {
                .name = "http.max-redirs",
                .type = &gt_uint,
                .offset = offsetof(struct rpki_config, http.max_redirs),
-               .doc = "Maximum number of redirections to follow, per request.",
+               .doc = "Maximum number of redirections to follow, per HTTP request.",
                .min = 0,
                .max = UINT_MAX,
        }, {
index a89caa724ab132f42ef9a4a64d287e49046301f2..973243e5a1124401c2df39739cc72e7940036a2e 100644 (file)
@@ -112,6 +112,7 @@ json_get_ts(json_t *parent, char const *name, time_t *result)
        if (error)
                return error;
 
+       memset(&tm, 0, sizeof(tm));
        consumed = strptime(str, "%FT%T%z", &tm);
        if (consumed == NULL || (*consumed) != 0)
                return pr_op_err("String '%s' does not appear to be a timestamp.",
index 01d23d3caeaf77a14bb38198d0f5a85c992bda26..b4d6222302ef3b4d1eae06697f5e6b9dea2563ab 100644 (file)
@@ -115,7 +115,7 @@ prepare_rsync(struct rpki_uri *uri, char ***args, size_t *args_len)
                if (strcmp(config_args->array[i], "$REMOTE") == 0)
                        copy_args[i + 1] = pstrdup(uri_get_global(uri));
                else if (strcmp(config_args->array[i], "$LOCAL") == 0)
-                       copy_args[i + 1] = pstrdup(get_target(uri));
+                       copy_args[i + 1] = get_target(uri);
                else
                        copy_args[i + 1] = pstrdup(config_args->array[i]);
        }