Implement and use git_pkt_free A git_pkt object can be one of several structs. Add this function for convenience and clarity. 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
diff --git a/include/git2/pkt.h b/include/git2/pkt.h
index 7d61d4d..d0ffa55 100644
--- a/include/git2/pkt.h
+++ b/include/git2/pkt.h
@@ -56,3 +56,4 @@ struct git_pkt_ref {
*/
int git_pkt_gen_proto(char **out, int *outlen, const char *url);
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out);
+void git_pkt_free(git_pkt *pkt);
diff --git a/src/pkt.c b/src/pkt.c
index 023196a..f77bc30 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -173,6 +173,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out)
return error;
}
+void git_pkt_free(git_pkt *pkt)
+{
+ if(pkt->type == GIT_PKT_REF) {
+ git_pkt_ref *p = (git_pkt_ref *) pkt;
+ free(p->capabilities);
+ free(p->head.name);
+ }
+
+ free(pkt);
+}
+
/*
* Create a git procol request.
*
diff --git a/src/transport_git.c b/src/transport_git.c
index 526292c..ed72031 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -286,12 +286,7 @@ static void git_free(git_transport *transport)
for (i = 0; i < refs->length; ++i) {
git_pkt *p = git_vector_get(refs, i);
- if (p->type == GIT_PKT_REF) {
- free(((git_pkt_ref *)p)->head.name);
- free(((git_pkt_ref *)p)->capabilities);
- }
-
- free(p);
+ git_pkt_free(p);
}
git_vector_free(refs);