From: Alberto Leiva Popper Date: Fri, 17 Nov 2023 22:04:28 +0000 (-0600) Subject: Patch some memory leaks X-Git-Tag: 1.6.0~9 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=23bec30d3706ab7a9be225ef0eaaabcbbd29ebd3;p=thirdparty%2FFORT-validator.git Patch some memory leaks --- diff --git a/src/cache/local_cache.c b/src/cache/local_cache.c index f6116b9d..9d0a619f 100644 --- a/src/cache/local_cache.c +++ b/src/cache/local_cache.c @@ -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 * diff --git a/src/config.c b/src/config.c index 0ce330ad..c0ca15b7 100644 --- a/src/config.c +++ b/src/config.c @@ -522,7 +522,7 @@ static const struct option_field options[] = { .name = "http.max-redirs", .type = >_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, }, { diff --git a/src/json_util.c b/src/json_util.c index a89caa72..973243e5 100644 --- a/src/json_util.c +++ b/src/json_util.c @@ -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.", diff --git a/src/rsync/rsync.c b/src/rsync/rsync.c index 01d23d3c..b4d62223 100644 --- a/src/rsync/rsync.c +++ b/src/rsync/rsync.c @@ -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]); }