net: plug a few memory leaks Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
diff --git a/src/transport-http.c b/src/transport-http.c
index 13a95db..3426b34 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -389,15 +389,20 @@ static int on_body_parse_response(http_parser *parser, const char *str, size_t l
git_buf_consume(buf, line_end);
if (pkt->type == GIT_PKT_PACK) {
+ free(pkt);
t->pack_ready = 1;
return 0;
}
- if (pkt->type == GIT_PKT_NAK)
+ if (pkt->type == GIT_PKT_NAK) {
+ free(pkt);
return 0;
+ }
- if (pkt->type != GIT_PKT_ACK)
+ if (pkt->type != GIT_PKT_ACK) {
+ free(pkt);
continue;
+ }
error = git_vector_insert(common, pkt);
if (error < GIT_SUCCESS)
@@ -596,6 +601,8 @@ static int http_negotiate_fetch(git_transport *transport, git_repository *repo,
} while(1);
cleanup:
+ git_buf_free(&request);
+ git_buf_free(&data);
git_revwalk_free(walk);
return error;
}
@@ -722,6 +729,7 @@ static void http_free(git_transport *transport)
{
transport_http *t = (transport_http *) transport;
git_vector *refs = &t->refs;
+ git_vector *common = &t->common;
unsigned int i;
git_pkt *p;
@@ -737,6 +745,10 @@ static void http_free(git_transport *transport)
git_pkt_free(p);
}
git_vector_free(refs);
+ git_vector_foreach(common, i, p) {
+ git_pkt_free(p);
+ }
+ git_vector_free(common);
git_buf_free(&t->buf);
free(t->heads);
free(t->content_type);
diff --git a/src/transport_git.c b/src/transport_git.c
index 7b65936..4898078 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -357,9 +357,11 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
gitno_consume(buf, line_end);
if (pkt->type == GIT_PKT_ACK) {
+ free(pkt);
error = GIT_SUCCESS;
goto done;
} else if (pkt->type == GIT_PKT_NAK) {
+ free(pkt);
break;
} else {
error = git__throw(GIT_ERROR, "Got unexpected pkt type");
@@ -422,6 +424,7 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
return error;
if (pkt->type == GIT_PKT_PACK) {
+ free(pkt);
return git_fetch__download_pack(out, buf->data, buf->offset, t->socket, repo);
}