]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-pack: always allocate receive status
authorPatrick Steinhardt <ps@pks.im>
Fri, 7 Jun 2024 06:38:58 +0000 (08:38 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:30:53 +0000 (10:30 -0700)
In `receive_status()`, we record the reason why ref updates have been
rejected by the remote via the `remote_status`. But while we allocate
the assigned string when a reason was given, we assign a string constant
when no reason was given.

This has been working fine so far due to two reasons:

  - We don't ever free the refs in git-send-pack(1)'

  - Remotes always give a reason, at least as implemented by Git proper.

Adapt the code to always allocate the receive status string and free the
refs.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/send-pack.c
send-pack.c

index 3df9eaad092babdbbfc47f1c5441fc43a4ccd182..17cae6bbbdf298918ba75e7e78c73b1e5d154778 100644 (file)
@@ -336,5 +336,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
                /* stable plumbing output; do not modify or localize */
                fprintf(stderr, "Everything up-to-date\n");
 
+       free_refs(remote_refs);
+       free_refs(local_refs);
        return ret;
 }
index 37f59d4f66bbc2b21bf08288a75de4a159b24625..88e96d000b36cb599ea78b17c32fa87e6e8861d2 100644 (file)
@@ -259,7 +259,7 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
                        if (p)
                                hint->remote_status = xstrdup(p);
                        else
-                               hint->remote_status = "failed";
+                               hint->remote_status = xstrdup("failed");
                } else {
                        hint->status = REF_STATUS_OK;
                        hint->remote_status = xstrdup_or_null(p);