]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remote: fix leaking push reports
authorPatrick Steinhardt <ps@pks.im>
Mon, 30 Sep 2024 09:14:21 +0000 (11:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Sep 2024 18:23:08 +0000 (11:23 -0700)
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>
builtin/receive-pack.c
remote.c
remote.h

index 536d22761d6d9e5a2a6645ab7a68e29f07b9bfa3..ab5b20e39c5038cdf6e6f05f4d66278a9c1ac156 100644 (file)
@@ -374,6 +374,7 @@ static void write_head_info(void)
 struct command {
        struct command *next;
        const char *error_string;
+       char *error_string_owned;
        struct ref_push_report *report;
        unsigned int skip_update:1,
                     did_not_exist:1,
@@ -1083,7 +1084,7 @@ static int read_proc_receive_report(struct packet_reader *reader,
                hint->run_proc_receive |= RUN_PROC_RECEIVE_RETURNED;
                if (!strcmp(head, "ng")) {
                        if (p)
-                               hint->error_string = xstrdup(p);
+                               hint->error_string = hint->error_string_owned = xstrdup(p);
                        else
                                hint->error_string = "failed";
                        code = -1;
@@ -2054,6 +2055,8 @@ static void free_commands(struct command *commands)
        while (commands) {
                struct command *next = commands->next;
 
+               ref_push_report_free(commands->report);
+               free(commands->error_string_owned);
                free(commands);
                commands = next;
        }
index e291e8ff5cddb25e35063be74097b1965b27000e..cd2091ac0ceac4c983ad6e02019ef477768e7e04 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -868,6 +868,20 @@ struct strvec *push_url_of_remote(struct remote *remote)
        return remote->pushurl.nr ? &remote->pushurl : &remote->url;
 }
 
+void ref_push_report_free(struct ref_push_report *report)
+{
+       while (report) {
+               struct ref_push_report *next = report->next;
+
+               free(report->ref_name);
+               free(report->old_oid);
+               free(report->new_oid);
+               free(report);
+
+               report = next;
+       }
+}
+
 static int match_name_with_pattern(const char *key, const char *name,
                                   const char *value, char **result)
 {
@@ -1122,6 +1136,7 @@ void free_one_ref(struct ref *ref)
        if (!ref)
                return;
        free_one_ref(ref->peer_ref);
+       ref_push_report_free(ref->report);
        free(ref->remote_status);
        free(ref->tracking_ref);
        free(ref->symref);
index ad4513f6394bed26561bf0de918d0e2e827de28c..c5e79eb40ee80ffa7ef7c9c4ab8cc18f56173a81 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -126,13 +126,15 @@ int remote_has_url(struct remote *remote, const char *url);
 struct strvec *push_url_of_remote(struct remote *remote);
 
 struct ref_push_report {
-       const char *ref_name;
+       char *ref_name;
        struct object_id *old_oid;
        struct object_id *new_oid;
        unsigned int forced_update:1;
        struct ref_push_report *next;
 };
 
+void ref_push_report_free(struct ref_push_report *);
+
 struct ref {
        struct ref *next;
        struct object_id old_oid;