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>
This commit is contained in:
Carlos Martín Nieto 2011-06-08 23:38:22 +02:00
parent ecb6ca0e1f
commit be9fe679fc
3 changed files with 13 additions and 6 deletions

View File

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

View File

@ -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.
*

View File

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