Skip to content

Commit 8f7fc2e

Browse files
committed
shallow: avoid unnecessary pkt free
Looks like a double-free here.
1 parent d69c7a7 commit 8f7fc2e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/libgit2/transports/smart_protocol.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,28 @@ int git_smart__negotiate_fetch(git_transport *transport, git_repository *repo, c
408408
goto on_error;
409409

410410
while ((error = recv_pkt((git_pkt **)&pkt, NULL, t, buf)) == 0) {
411+
bool complete = false;
412+
411413
if (pkt->type == GIT_PKT_SHALLOW) {
412414
git_shallowarray_add(wants->shallow_roots, &pkt->oid);
413415
} else if (pkt->type == GIT_PKT_UNSHALLOW) {
414416
git_shallowarray_remove(wants->shallow_roots, &pkt->oid);
415417
} else if (pkt->type == GIT_PKT_FLUSH) {
416418
/* Server is done, stop processing shallow oids */
417-
break;
419+
complete = true;
418420
} else {
419-
git_error_set(GIT_ERROR_NET, "Unexpected pkt type");
420-
goto on_error;
421+
git_error_set(GIT_ERROR_NET, "unexpected packet type");
422+
error = -1;
421423
}
422424

423425
git_pkt_free((git_pkt *) pkt);
424-
}
425426

426-
git_pkt_free((git_pkt *) pkt);
427+
if (complete || error < 0)
428+
break;
429+
}
427430

428-
if (error < 0) {
431+
if (error < 0)
429432
goto on_error;
430-
}
431433
}
432434
/*
433435
* Our support for ACK extensions is simply to parse them. On

0 commit comments

Comments
 (0)