summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2016-02-22 15:52:49 +0100
committerPatrick Steinhardt <ps@pks.im>2016-02-23 11:50:23 +0100
commit003c5e46a84ec7ecee134b9471e6c84ba673847d (patch)
treeeb1ad4b3ace5e2284e8fed6a8d8d8a5ac4757d03
parent793e0855365bbabfeffbd730fd9ee5ee9a011546 (diff)
downloadlibgit2-003c5e46a84ec7ecee134b9471e6c84ba673847d.tar.gz
transports: smart_pkt: fix memory leaks on error paths
-rw-r--r--src/transports/smart_pkt.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 2c33916c7..2ea57bb64 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -296,13 +296,12 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
pkt = git__malloc(sizeof(*pkt));
GITERR_CHECK_ALLOC(pkt);
+ pkt->ref = NULL;
pkt->type = GIT_PKT_NG;
line += 3; /* skip "ng " */
- if (!(ptr = strchr(line, ' '))) {
- giterr_set(GITERR_NET, "Invalid packet line");
- return -1;
- }
+ if (!(ptr = strchr(line, ' ')))
+ goto out_err;
len = ptr - line;
GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1);
@@ -313,12 +312,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
pkt->ref[len] = '\0';
line = ptr + 1;
- if (!(ptr = strchr(line, '\n'))) {
- giterr_set(GITERR_NET, "Invalid packet line");
- git__free(pkt->ref);
- git__free(pkt);
- return -1;
- }
+ if (!(ptr = strchr(line, '\n')))
+ goto out_err;
len = ptr - line;
GITERR_CHECK_ALLOC_ADD(&alloclen, len, 1);
@@ -330,6 +325,12 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
*out = (git_pkt *)pkt;
return 0;
+
+out_err:
+ giterr_set(GITERR_NET, "Invalid packet line");
+ git__free(pkt->ref);
+ git__free(pkt);
+ return -1;
}
static int unpack_pkt(git_pkt **out, const char *line, size_t len)