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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 30, 2024 at 11:14 UTC
a6c30623d77b5fe759d5d9bedc33957ddaff1b4d
3 files changed
+22
-2
builtin/receive-pack.c
+4
-1
@@ -374,6 +374,7 @@ static void write_head_info(void)
374
struct command {
375
struct command *next;
376
const char *error_string;
377
+ char *error_string_owned;
378
struct ref_push_report *report;
379
unsigned int skip_update:1,
380
did_not_exist:1,
@@ -1083,7 +1084,7 @@ static int read_proc_receive_report(struct packet_reader *reader,
1084
hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
1085
if (!strcmp(head, "ng")) {
1086
if (p)
1086
- hint->error_string = xstrdup(p);
1087
+ hint->error_string = hint->error_string_owned = xstrdup(p);
1088
else
1089
hint->error_string = "failed";
1090
code = -1;
@@ -2054,6 +2055,8 @@ static void free_commands(struct command *commands)
2055
while (commands) {
2056
struct command *next = commands->next;
2057
2058
+ ref_push_report_free(commands->report);
2059
+ free(commands->error_string_owned);
2060
free(commands);
2061
commands = next;
2062
}
remote.c
+15
@@ -868,6 +868,20 @@ struct strvec *push_url_of_remote(struct remote *remote)
868
return remote->pushurl.nr ? &remote->pushurl : &remote->url;
869
}
870
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
+
885
static int match_name_with_pattern(const char *key, const char *name,
886
const char *value, char **result)
887
{
@@ -1122,6 +1136,7 @@ void free_one_ref(struct ref *ref)
1136
if (!ref)
1137
return;
1138
free_one_ref(ref->peer_ref);
1139
+ ref_push_report_free(ref->report);
1140
free(ref->remote_status);
1141
free(ref->tracking_ref);
1142
free(ref->symref);
remote.h
+3
-1
@@ -126,13 +126,15 @@ int remote_has_url(struct remote *remote, const char *url);
126
struct strvec *push_url_of_remote(struct remote *remote);
127
128
struct ref_push_report {
129
- const char *ref_name;
129
+ char *ref_name;
130
struct object_id *old_oid;
131
struct object_id *new_oid;
132
unsigned int forced_update:1;
133
struct ref_push_report *next;
134
};
135
136
+void ref_push_report_free(struct ref_push_report *);
137
+
138
struct ref {
139
struct ref *next;
140
struct object_id old_oid;