Skip to content

Commit 4c4408c

Browse files
committed
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.
1 parent a598264 commit 4c4408c

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ static int update_head_to_new_branch(
113113
const char *reflog_message)
114114
{
115115
git_reference *tracking_branch = NULL;
116+
int error;
116117

117118
if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
118119
name += strlen(GIT_REFS_HEADS_DIR);
119120

120-
int error = create_tracking_branch(&tracking_branch, repo, target, name,
121+
error = create_tracking_branch(&tracking_branch, repo, target, name,
121122
signature, reflog_message);
122123

123124
if (!error)

src/transports/local.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ typedef struct {
4040
have_refs : 1;
4141
} transport_local;
4242

43+
static void free_head(git_remote_head *head)
44+
{
45+
git__free(head->name);
46+
git__free(head->symref_target);
47+
git__free(head);
48+
}
49+
4350
static int add_ref(transport_local *t, const char *name)
4451
{
4552
const char peeled[] = "^{}";
@@ -83,8 +90,7 @@ static int add_ref(transport_local *t, const char *name)
8390
git_reference_free(ref);
8491

8592
if ((error = git_vector_insert(&t->refs, head)) < 0) {
86-
git__free(head->name);
87-
git__free(head);
93+
free_head(head);
8894
return error;
8995
}
9096

@@ -117,8 +123,7 @@ static int add_ref(transport_local *t, const char *name)
117123
git_oid_cpy(&head->oid, git_object_id(target));
118124

119125
if ((error = git_vector_insert(&t->refs, head)) < 0) {
120-
git__free(head->name);
121-
git__free(head);
126+
free_head(head);
122127
}
123128
}
124129

@@ -640,10 +645,8 @@ static void local_free(git_transport *transport)
640645
size_t i;
641646
git_remote_head *head;
642647

643-
git_vector_foreach(&t->refs, i, head) {
644-
git__free(head->name);
645-
git__free(head);
646-
}
648+
git_vector_foreach(&t->refs, i, head)
649+
free_head(head);
647650

648651
git_vector_free(&t->refs);
649652

src/transports/smart_protocol.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ int git_smart__store_refs(transport_smart *t, int flushes)
2626
int error, flush = 0, recvd;
2727
const char *line_end = NULL;
2828
git_pkt *pkt = NULL;
29-
git_pkt_ref *ref;
3029
size_t i;
3130

3231
/* Clear existing refs in case git_remote_connect() is called again
3332
* after git_remote_disconnect().
3433
*/
35-
git_vector_foreach(refs, i, ref) {
36-
git__free(ref->head.name);
37-
git__free(ref);
34+
git_vector_foreach(refs, i, pkt) {
35+
git_pkt_free(pkt);
3836
}
3937
git_vector_clear(refs);
38+
pkt = NULL;
4039

4140
do {
4241
if (buf->offset > 0)

0 commit comments

Comments
 (0)