git_pkt_free: Allow freeing NULL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 4824330..d0151a7 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -370,7 +370,7 @@ static int32_t parse_len(const char *line)
num[k] = '.';
}
}
-
+
giterr_set(GITERR_NET, "invalid hex digit in length: '%s'", num);
return -1;
}
@@ -483,6 +483,9 @@ int git_pkt_parse_line(
void git_pkt_free(git_pkt *pkt)
{
+ if (pkt == NULL) {
+ return;
+ }
if (pkt->type == GIT_PKT_REF) {
git_pkt_ref *p = (git_pkt_ref *) pkt;
git__free(p->head.name);
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index dd2d27e..943ee75 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -321,9 +321,7 @@ static int wait_while_ack(gitno_buffer *buf)
git_pkt_ack *ack = NULL;
while (1) {
- if (pkt) {
- git_pkt_free(pkt);
- }
+ git_pkt_free(pkt);
if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
return error;
@@ -342,9 +340,7 @@ static int wait_while_ack(gitno_buffer *buf)
}
}
- if (pkt) {
- git_pkt_free(pkt);
- }
+ git_pkt_free(pkt);
return 0;
}
@@ -622,9 +618,8 @@ int git_smart__download_pack(
}
}
- if (pkt) {
- git_pkt_free(pkt);
- }
+ git_pkt_free(pkt);
+
if (error < 0)
goto done;