Skip to content

Commit a6c3062

Browse files
pks-tgitster
authored andcommitted
remote: fix leaking push reports
The push reports that report failures to the user when pushing a reference leak in several places. Plug these leaks by introducing a new function `ref_push_report_free()` that frees the list of reports and call it as required. While at it, fix a trivially leaking error string in the vicinity. These leaks get hit in t5411, but plugging them does not make the whole test suite pass. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 12f0fb9 commit a6c3062

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

builtin/receive-pack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static void write_head_info(void)
374374
struct command {
375375
struct command *next;
376376
const char *error_string;
377+
char *error_string_owned;
377378
struct ref_push_report *report;
378379
unsigned int skip_update:1,
379380
did_not_exist:1,
@@ -1083,7 +1084,7 @@ static int read_proc_receive_report(struct packet_reader *reader,
10831084
hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
10841085
if (!strcmp(head, "ng")) {
10851086
if (p)
1086-
hint->error_string = xstrdup(p);
1087+
hint->error_string = hint->error_string_owned = xstrdup(p);
10871088
else
10881089
hint->error_string = "failed";
10891090
code = -1;
@@ -2054,6 +2055,8 @@ static void free_commands(struct command *commands)
20542055
while (commands) {
20552056
struct command *next = commands->next;
20562057

2058+
ref_push_report_free(commands->report);
2059+
free(commands->error_string_owned);
20572060
free(commands);
20582061
commands = next;
20592062
}

remote.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,20 @@ struct strvec *push_url_of_remote(struct remote *remote)
868868
return remote->pushurl.nr ? &remote->pushurl : &remote->url;
869869
}
870870

871+
void ref_push_report_free(struct ref_push_report *report)
872+
{
873+
while (report) {
874+
struct ref_push_report *next = report->next;
875+
876+
free(report->ref_name);
877+
free(report->old_oid);
878+
free(report->new_oid);
879+
free(report);
880+
881+
report = next;
882+
}
883+
}
884+
871885
static int match_name_with_pattern(const char *key, const char *name,
872886
const char *value, char **result)
873887
{
@@ -1122,6 +1136,7 @@ void free_one_ref(struct ref *ref)
11221136
if (!ref)
11231137
return;
11241138
free_one_ref(ref->peer_ref);
1139+
ref_push_report_free(ref->report);
11251140
free(ref->remote_status);
11261141
free(ref->tracking_ref);
11271142
free(ref->symref);

remote.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ int remote_has_url(struct remote *remote, const char *url);
126126
struct strvec *push_url_of_remote(struct remote *remote);
127127

128128
struct ref_push_report {
129-
const char *ref_name;
129+
char *ref_name;
130130
struct object_id *old_oid;
131131
struct object_id *new_oid;
132132
unsigned int forced_update:1;
133133
struct ref_push_report *next;
134134
};
135135

136+
void ref_push_report_free(struct ref_push_report *);
137+
136138
struct ref {
137139
struct ref *next;
138140
struct object_id old_oid;

0 commit comments

Comments
 (0)