Skip to content

Commit 1f08999

Browse files
pks-tgitster
authored andcommitted
entry: fix leaking pathnames during delayed checkout
When filtering files during delayed checkout, we pass a string list to `async_query_available_blobs()`. This list is initialized with NODUP, and thus inserted strings will not be owned by the list. In the latter function we then try to hand over ownership by passing an `xstrup()`'d value to `string_list_insert()`. But this is not how this works: a NODUP list does not take ownership of allocated strings and will never free them for the caller. Fix this issue by initializing the list as `DUP` instead and dropping the explicit call to `xstrdup()`. This is okay to do given that this is the single callsite of `async_query_available_blobs()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57fb139 commit 1f08999

4 files changed

+6
-2
lines changed

convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ int async_query_available_blobs(const char *cmd, struct string_list *available_p
960960
while ((line = packet_read_line(process->out, NULL))) {
961961
const char *path;
962962
if (skip_prefix(line, "pathname=", &path))
963-
string_list_insert(available_paths, xstrdup(path));
963+
string_list_insert(available_paths, path);
964964
else
965965
; /* ignore unknown keys */
966966
}

entry.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
191191
progress = start_delayed_progress(_("Filtering content"), dco->paths.nr);
192192
while (dco->filters.nr > 0) {
193193
for_each_string_list_item(filter, &dco->filters) {
194-
struct string_list available_paths = STRING_LIST_INIT_NODUP;
194+
struct string_list available_paths = STRING_LIST_INIT_DUP;
195195

196196
if (!async_query_available_blobs(filter->string, &available_paths)) {
197197
/* Filter reported an error */
@@ -245,6 +245,8 @@ int finish_delayed_checkout(struct checkout *state, int show_progress)
245245
} else
246246
errs = 1;
247247
}
248+
249+
string_list_clear(&available_paths, 0);
248250
}
249251

250252
filter_string_list(&dco->filters, 0, string_is_not_null, NULL);

t/t2080-parallel-checkout-basics.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ working tree.
88
'
99

1010
TEST_NO_CREATE_REPO=1
11+
TEST_PASSES_SANITIZE_LEAK=true
1112
. ./test-lib.sh
1213
. "$TEST_DIRECTORY/lib-parallel-checkout.sh"
1314

t/t2082-parallel-checkout-attributes.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ properly (without access to the index or attribute stack).
1010
'
1111

1212
TEST_NO_CREATE_REPO=1
13+
TEST_PASSES_SANITIZE_LEAK=true
1314
. ./test-lib.sh
1415
. "$TEST_DIRECTORY/lib-parallel-checkout.sh"
1516
. "$TEST_DIRECTORY/lib-encoding.sh"

0 commit comments

Comments
 (0)