summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-24 11:16:47 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-05-08 15:06:38 +0100
commit8f7fc2ee505a0abe2186270a79b287e321c748c4 (patch)
treeebd91ceacf22f943535048697b59255fc712cd5c
parentd69c7a72386c9e01f4b0c8945724f870bf9aa4f6 (diff)
downloadlibgit2-8f7fc2ee505a0abe2186270a79b287e321c748c4.tar.gz
shallow: avoid unnecessary pkt free
Looks like a double-free here.
-rw-r--r--src/libgit2/transports/smart_protocol.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/libgit2/transports/smart_protocol.c b/src/libgit2/transports/smart_protocol.c
index eb2bc5be4..6167a8074 100644
--- a/src/libgit2/transports/smart_protocol.c
+++ b/src/libgit2/transports/smart_protocol.c
@@ -408,26 +408,28 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
goto on_error;
while ((error = recv_pkt((git_pkt **)&pkt, NULL, t, buf)) == 0) {
+ bool complete = false;
+
if (pkt->type == GIT_PKT_SHALLOW) {
git_shallowarray_add(wants->shallow_roots, &pkt->oid);
} else if (pkt->type == GIT_PKT_UNSHALLOW) {
git_shallowarray_remove(wants->shallow_roots, &pkt->oid);
} else if (pkt->type == GIT_PKT_FLUSH) {
/* Server is done, stop processing shallow oids */
- break;
+ complete = true;
} else {
- git_error_set(GIT_ERROR_NET, "Unexpected pkt type");
- goto on_error;
+ git_error_set(GIT_ERROR_NET, "unexpected packet type");
+ error = -1;
}
git_pkt_free((git_pkt *) pkt);
- }
- git_pkt_free((git_pkt *) pkt);
+ if (complete || error < 0)
+ break;
+ }
- if (error < 0) {
+ if (error < 0)
goto on_error;
- }
}
/*
* Our support for ACK extensions is simply to parse them. On