diff --git a/remote-curl.c b/remote-curl.c index b2898809bd9f6a..c2068eaf1ea180 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -212,6 +212,7 @@ static int set_option(const char *name, size_t namelen, const char *value) options.refetch = 1; return 0; } else if (!strncmp(name, "filter", namelen)) { + free(options.filter); options.filter = xstrdup(value); return 0; } else if (!strncmp(name, "object-format", namelen)) { diff --git a/sub-process.c b/sub-process.c index 29a65f8aebbd9d..86a0d3084b75d9 100644 --- a/sub-process.c +++ b/sub-process.c @@ -63,6 +63,8 @@ void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry) finish_command(&entry->process); hashmap_remove(hashmap, &entry->ent, NULL); + FREE_AND_NULL(entry->to_free); + entry->cmd = NULL; } static void subprocess_exit_handler(struct child_process *process) @@ -100,6 +102,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co process->trace2_child_class = "subprocess"; entry->cmd = process->args.v[0]; + entry->to_free = NULL; err = start_command(process); if (err) { @@ -145,11 +148,13 @@ int subprocess_start_strvec(struct hashmap *hashmap, process->trace2_child_class = "subprocess"; sq_quote_argv_pretty("ed, argv->v); - entry->cmd = strbuf_detach("ed, NULL); + entry->cmd = entry->to_free = strbuf_detach("ed, NULL); err = start_command(process); if (err) { error("cannot fork to run subprocess '%s'", entry->cmd); + FREE_AND_NULL(entry->to_free); + entry->cmd = NULL; return err; } @@ -158,6 +163,8 @@ int subprocess_start_strvec(struct hashmap *hashmap, err = startfn(entry); if (err) { error("initialization for subprocess '%s' failed", entry->cmd); + FREE_AND_NULL(entry->to_free); + entry->cmd = NULL; subprocess_stop(hashmap, entry); return err; } diff --git a/sub-process.h b/sub-process.h index 73cc536646df79..926d43ae2d2054 100644 --- a/sub-process.h +++ b/sub-process.h @@ -25,6 +25,12 @@ struct subprocess_entry { struct hashmap_entry ent; const char *cmd; + /** + * In case `cmd` is a `strdup()`ed value that needs to be released, + * you can assign the pointer to `to_free` so that `subprocess_stop()` + * will release it. + */ + char *to_free; struct child_process process; }; diff --git a/transport-helper.c b/transport-helper.c index 7513fd7eea05e4..5459010f44b54e 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -404,6 +404,7 @@ static int release_helper(struct transport *transport) free(data->import_marks); free(data->export_marks); res = disconnect_helper(transport); + list_objects_filter_release(&data->transport_options.filter_options); free(transport->data); return res; }