Commit be9fe679 by Carlos Martín Nieto

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>
parent ecb6ca0e
...@@ -56,3 +56,4 @@ struct git_pkt_ref { ...@@ -56,3 +56,4 @@ struct git_pkt_ref {
*/ */
int git_pkt_gen_proto(char **out, int *outlen, const char *url); 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); int git_pkt_parse_line(git_pkt **head, const char *line, const char **out);
void git_pkt_free(git_pkt *pkt);
...@@ -173,6 +173,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out) ...@@ -173,6 +173,17 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out)
return error; 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. * Create a git procol request.
* *
......
...@@ -286,12 +286,7 @@ static void git_free(git_transport *transport) ...@@ -286,12 +286,7 @@ static void git_free(git_transport *transport)
for (i = 0; i < refs->length; ++i) { for (i = 0; i < refs->length; ++i) {
git_pkt *p = git_vector_get(refs, i); git_pkt *p = git_vector_get(refs, i);
if (p->type == GIT_PKT_REF) { git_pkt_free(p);
free(((git_pkt_ref *)p)->head.name);
free(((git_pkt_ref *)p)->capabilities);
}
free(p);
} }
git_vector_free(refs); git_vector_free(refs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment