Skip to content

Commit e06c1d1

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4119fc0 commit e06c1d1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/remote.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct branch_info {
258258
char *push_remote_name;
259259
};
260260

261-
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
261+
static struct string_list branch_list = STRING_LIST_INIT_DUP;
262262

263263
static const char *abbrev_ref(const char *name, const char *prefix)
264264
{
@@ -292,8 +292,8 @@ static int config_read_branches(const char *key, const char *value,
292292
type = PUSH_REMOTE;
293293
else
294294
return 0;
295-
name = xmemdupz(key, key_len);
296295

296+
name = xmemdupz(key, key_len);
297297
item = string_list_insert(&branch_list, name);
298298

299299
if (!item->util)
@@ -337,6 +337,7 @@ static int config_read_branches(const char *key, const char *value,
337337
BUG("unexpected type=%d", type);
338338
}
339339

340+
free(name);
340341
return 0;
341342
}
342343

0 commit comments

Comments
 (0)