summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-22 12:28:39 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-22 12:28:39 +0200
commit4c4408c351650dac84c81a67a321a4d92cc85ffa (patch)
tree4fc65c781b55e7092f8e58b34a5c5bd65f2af7f6
parenta598264463442da0013d6e8b6a0c93d075e14d3a (diff)
downloadlibgit2-4c4408c351650dac84c81a67a321a4d92cc85ffa.tar.gz
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.
-rw-r--r--src/clone.c3
-rw-r--r--src/transports/local.c19
-rw-r--r--src/transports/smart_protocol.c7
3 files changed, 16 insertions, 13 deletions
diff --git a/src/clone.c b/src/clone.c
index f19771c1e..8381ec63c 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -113,11 +113,12 @@ static int update_head_to_new_branch(
const char *reflog_message)
{
git_reference *tracking_branch = NULL;
+ int error;
if (!git__prefixcmp(name, 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);
if (!error)
diff --git a/src/transports/local.c b/src/transports/local.c
index 8d3619388..038337d72 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -40,6 +40,13 @@ typedef struct {
have_refs : 1;
} 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)
{
const char peeled[] = "^{}";
@@ -83,8 +90,7 @@ static int add_ref(transport_local *t, const char *name)
git_reference_free(ref);
if ((error = git_vector_insert(&t->refs, head)) < 0) {
- git__free(head->name);
- git__free(head);
+ free_head(head);
return error;
}
@@ -117,8 +123,7 @@ static int add_ref(transport_local *t, const char *name)
git_oid_cpy(&head->oid, git_object_id(target));
if ((error = git_vector_insert(&t->refs, head)) < 0) {
- git__free(head->name);
- git__free(head);
+ free_head(head);
}
}
@@ -640,10 +645,8 @@ static void local_free(git_transport *transport)
size_t i;
git_remote_head *head;
- git_vector_foreach(&t->refs, i, head) {
- git__free(head->name);
- git__free(head);
- }
+ git_vector_foreach(&t->refs, i, head)
+ free_head(head);
git_vector_free(&t->refs);
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index bab0cf113..a52aacc60 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -26,17 +26,16 @@ int git_smart__store_refs(transport_smart *t, int flushes)
int error, flush = 0, recvd;
const char *line_end = NULL;
git_pkt *pkt = NULL;
- git_pkt_ref *ref;
size_t i;
/* Clear existing refs in case git_remote_connect() is called again
* after git_remote_disconnect().
*/
- git_vector_foreach(refs, i, ref) {
- git__free(ref->head.name);
- git__free(ref);
+ git_vector_foreach(refs, i, pkt) {
+ git_pkt_free(pkt);
}
git_vector_clear(refs);
+ pkt = NULL;
do {
if (buf->offset > 0)