Skip to content

Commit 5badd55

Browse files
dschomjcheetham
authored andcommitted
Merge branch 'leak-fixes'
Git v2.48.0 has become even more stringent about leaks. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 4ebf0ec + 4d937ce commit 5badd55

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

remote-curl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static int set_option(const char *name, size_t namelen, const char *value)
212212
options.refetch = 1;
213213
return 0;
214214
} else if (!strncmp(name, "filter", namelen)) {
215+
free(options.filter);
215216
options.filter = xstrdup(value);
216217
return 0;
217218
} else if (!strncmp(name, "object-format", namelen)) {

sub-process.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)
6363
finish_command(&entry->process);
6464

6565
hashmap_remove(hashmap, &entry->ent, NULL);
66+
FREE_AND_NULL(entry->to_free);
67+
entry->cmd = NULL;
6668
}
6769

6870
static void subprocess_exit_handler(struct child_process *process)
@@ -100,6 +102,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
100102
process->trace2_child_class = "subprocess";
101103

102104
entry->cmd = process->args.v[0];
105+
entry->to_free = NULL;
103106

104107
err = start_command(process);
105108
if (err) {
@@ -145,11 +148,13 @@ int subprocess_start_strvec(struct hashmap *hashmap,
145148
process->trace2_child_class = "subprocess";
146149

147150
sq_quote_argv_pretty(&quoted, argv->v);
148-
entry->cmd = strbuf_detach(&quoted, NULL);
151+
entry->cmd = entry->to_free = strbuf_detach(&quoted, NULL);
149152

150153
err = start_command(process);
151154
if (err) {
152155
error("cannot fork to run subprocess '%s'", entry->cmd);
156+
FREE_AND_NULL(entry->to_free);
157+
entry->cmd = NULL;
153158
return err;
154159
}
155160

@@ -158,6 +163,8 @@ int subprocess_start_strvec(struct hashmap *hashmap,
158163
err = startfn(entry);
159164
if (err) {
160165
error("initialization for subprocess '%s' failed", entry->cmd);
166+
FREE_AND_NULL(entry->to_free);
167+
entry->cmd = NULL;
161168
subprocess_stop(hashmap, entry);
162169
return err;
163170
}

sub-process.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
struct subprocess_entry {
2626
struct hashmap_entry ent;
2727
const char *cmd;
28+
/**
29+
* In case `cmd` is a `strdup()`ed value that needs to be released,
30+
* you can assign the pointer to `to_free` so that `subprocess_stop()`
31+
* will release it.
32+
*/
33+
char *to_free;
2834
struct child_process process;
2935
};
3036

transport-helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ static int release_helper(struct transport *transport)
404404
free(data->import_marks);
405405
free(data->export_marks);
406406
res = disconnect_helper(transport);
407+
list_objects_filter_release(&data->transport_options.filter_options);
407408
free(transport->data);
408409
return res;
409410
}

0 commit comments

Comments
 (0)