Commit be9fe679fc86a8f233b0a6fc6078894edcb8661e

Carlos Martín Nieto 2011-06-08T23:38:22

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>

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);