Commit 4c4408c3 by Carlos Martín Nieto

Plug leaks and fix a C99-ism

We have too many places where we repeat free code, so when adding the
new free to the generic code, it didn't take for the local transport.

While there, fix a C99-ism that sneaked through.
parent a5982644
...@@ -113,11 +113,12 @@ static int update_head_to_new_branch( ...@@ -113,11 +113,12 @@ static int update_head_to_new_branch(
const char *reflog_message) const char *reflog_message)
{ {
git_reference *tracking_branch = NULL; git_reference *tracking_branch = NULL;
int error;
if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR)) if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
name += strlen(GIT_REFS_HEADS_DIR); name += strlen(GIT_REFS_HEADS_DIR);
int error = create_tracking_branch(&tracking_branch, repo, target, name, error = create_tracking_branch(&tracking_branch, repo, target, name,
signature, reflog_message); signature, reflog_message);
if (!error) if (!error)
......
...@@ -40,6 +40,13 @@ typedef struct { ...@@ -40,6 +40,13 @@ typedef struct {
have_refs : 1; have_refs : 1;
} transport_local; } transport_local;
static void free_head(git_remote_head *head)
{
git__free(head->name);
git__free(head->symref_target);
git__free(head);
}
static int add_ref(transport_local *t, const char *name) static int add_ref(transport_local *t, const char *name)
{ {
const char peeled[] = "^{}"; const char peeled[] = "^{}";
...@@ -83,8 +90,7 @@ static int add_ref(transport_local *t, const char *name) ...@@ -83,8 +90,7 @@ static int add_ref(transport_local *t, const char *name)
git_reference_free(ref); git_reference_free(ref);
if ((error = git_vector_insert(&t->refs, head)) < 0) { if ((error = git_vector_insert(&t->refs, head)) < 0) {
git__free(head->name); free_head(head);
git__free(head);
return error; return error;
} }
...@@ -117,8 +123,7 @@ static int add_ref(transport_local *t, const char *name) ...@@ -117,8 +123,7 @@ static int add_ref(transport_local *t, const char *name)
git_oid_cpy(&head->oid, git_object_id(target)); git_oid_cpy(&head->oid, git_object_id(target));
if ((error = git_vector_insert(&t->refs, head)) < 0) { if ((error = git_vector_insert(&t->refs, head)) < 0) {
git__free(head->name); free_head(head);
git__free(head);
} }
} }
...@@ -640,10 +645,8 @@ static void local_free(git_transport *transport) ...@@ -640,10 +645,8 @@ static void local_free(git_transport *transport)
size_t i; size_t i;
git_remote_head *head; git_remote_head *head;
git_vector_foreach(&t->refs, i, head) { git_vector_foreach(&t->refs, i, head)
git__free(head->name); free_head(head);
git__free(head);
}
git_vector_free(&t->refs); git_vector_free(&t->refs);
......
...@@ -26,17 +26,16 @@ int git_smart__store_refs(transport_smart *t, int flushes) ...@@ -26,17 +26,16 @@ int git_smart__store_refs(transport_smart *t, int flushes)
int error, flush = 0, recvd; int error, flush = 0, recvd;
const char *line_end = NULL; const char *line_end = NULL;
git_pkt *pkt = NULL; git_pkt *pkt = NULL;
git_pkt_ref *ref;
size_t i; size_t i;
/* Clear existing refs in case git_remote_connect() is called again /* Clear existing refs in case git_remote_connect() is called again
* after git_remote_disconnect(). * after git_remote_disconnect().
*/ */
git_vector_foreach(refs, i, ref) { git_vector_foreach(refs, i, pkt) {
git__free(ref->head.name); git_pkt_free(pkt);
git__free(ref);
} }
git_vector_clear(refs); git_vector_clear(refs);
pkt = NULL;
do { do {
if (buf->offset > 0) if (buf->offset > 0)
......
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