builtin/remote: fix leaking strings in branch_list
The `struct string_list branch_list` is declared as `NODUP`, which makes it not copy strings inserted into it. This causes memory leaks though, as this means it also won't be responsible for _freeing_ inserted strings. Thus, every branch we add to this will leak. Fix this by marking the list as `DUP` instead and free the local copy we have of the variable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
4119fc08e2
commit
e06c1d1640
@@ -258,7 +258,7 @@ struct branch_info {
|
|||||||
char *push_remote_name;
|
char *push_remote_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
|
static struct string_list branch_list = STRING_LIST_INIT_DUP;
|
||||||
|
|
||||||
static const char *abbrev_ref(const char *name, const char *prefix)
|
static const char *abbrev_ref(const char *name, const char *prefix)
|
||||||
{
|
{
|
||||||
@@ -292,8 +292,8 @@ static int config_read_branches(const char *key, const char *value,
|
|||||||
type = PUSH_REMOTE;
|
type = PUSH_REMOTE;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
name = xmemdupz(key, key_len);
|
|
||||||
|
|
||||||
|
name = xmemdupz(key, key_len);
|
||||||
item = string_list_insert(&branch_list, name);
|
item = string_list_insert(&branch_list, name);
|
||||||
|
|
||||||
if (!item->util)
|
if (!item->util)
|
||||||
@@ -337,6 +337,7 @@ static int config_read_branches(const char *key, const char *value,
|
|||||||
BUG("unexpected type=%d", type);
|
BUG("unexpected type=%d", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user