Skip to content

Commit 7522bb9

Browse files
committed
Merge branch 'jk/plug-list-object-filter-leaks' into jk/list-objects-filter-cleanup
* jk/plug-list-object-filter-leaks: prepare_repo_settings(): plug leak of config values list_objects_filter_options: plug leak of filter_spec strings transport: free filter options in disconnect_git() transport: deep-copy object-filter struct for fetch-pack list_objects_filter_copy(): deep-copy sparse_oid_name field
2 parents ac8035a + 66eede4 commit 7522bb9

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

list-objects-filter-options.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static void filter_spec_append_urlencode(
207207
struct strbuf buf = STRBUF_INIT;
208208
strbuf_addstr_urlencode(&buf, raw, allow_unencoded);
209209
trace_printf("Add to combine filter-spec: %s\n", buf.buf);
210-
string_list_append(&filter->filter_spec, strbuf_detach(&buf, NULL));
210+
string_list_append_nodup(&filter->filter_spec, strbuf_detach(&buf, NULL));
211211
}
212212

213213
/*
@@ -226,12 +226,13 @@ static void transform_to_combine_type(
226226
xcalloc(initial_sub_alloc, sizeof(*sub_array));
227227
sub_array[0] = *filter_options;
228228
memset(filter_options, 0, sizeof(*filter_options));
229+
string_list_init_dup(&filter_options->filter_spec);
229230
filter_options->sub = sub_array;
230231
filter_options->sub_alloc = initial_sub_alloc;
231232
}
232233
filter_options->sub_nr = 1;
233234
filter_options->choice = LOFC_COMBINE;
234-
string_list_append(&filter_options->filter_spec, xstrdup("combine:"));
235+
string_list_append(&filter_options->filter_spec, "combine:");
235236
filter_spec_append_urlencode(
236237
filter_options,
237238
list_objects_filter_spec(&filter_options->sub[0]));
@@ -256,8 +257,14 @@ void parse_list_objects_filter(
256257
struct strbuf errbuf = STRBUF_INIT;
257258
int parse_error;
258259

260+
if (!filter_options->filter_spec.strdup_strings) {
261+
if (filter_options->filter_spec.nr)
262+
BUG("unexpected non-allocated string in filter_spec");
263+
filter_options->filter_spec.strdup_strings = 1;
264+
}
265+
259266
if (!filter_options->choice) {
260-
string_list_append(&filter_options->filter_spec, xstrdup(arg));
267+
string_list_append(&filter_options->filter_spec, arg);
261268

262269
parse_error = gently_parse_list_objects_filter(
263270
filter_options, arg, &errbuf);
@@ -268,7 +275,7 @@ void parse_list_objects_filter(
268275
*/
269276
transform_to_combine_type(filter_options);
270277

271-
string_list_append(&filter_options->filter_spec, xstrdup("+"));
278+
string_list_append(&filter_options->filter_spec, "+");
272279
filter_spec_append_urlencode(filter_options, arg);
273280
ALLOC_GROW_BY(filter_options->sub, filter_options->sub_nr, 1,
274281
filter_options->sub_alloc);
@@ -306,7 +313,7 @@ const char *list_objects_filter_spec(struct list_objects_filter_options *filter)
306313
strbuf_add_separated_string_list(
307314
&concatted, "", &filter->filter_spec);
308315
string_list_clear(&filter->filter_spec, /*free_util=*/0);
309-
string_list_append(
316+
string_list_append_nodup(
310317
&filter->filter_spec, strbuf_detach(&concatted, NULL));
311318
}
312319

@@ -321,7 +328,7 @@ const char *expand_list_objects_filter_spec(
321328
strbuf_addf(&expanded_spec, "blob:limit=%lu",
322329
filter->blob_limit_value);
323330
string_list_clear(&filter->filter_spec, /*free_util=*/0);
324-
string_list_append(
331+
string_list_append_nodup(
325332
&filter->filter_spec,
326333
strbuf_detach(&expanded_spec, NULL));
327334
}
@@ -418,6 +425,7 @@ void list_objects_filter_copy(
418425
string_list_init_dup(&dest->filter_spec);
419426
for_each_string_list_item(item, &src->filter_spec)
420427
string_list_append(&dest->filter_spec, item->string);
428+
dest->sparse_oid_name = xstrdup_or_null(src->sparse_oid_name);
421429

422430
ALLOC_ARRAY(dest->sub, dest->sub_alloc);
423431
for (i = 0; i < src->sub_nr; i++)

repo-settings.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void prepare_repo_settings(struct repository *r)
1515
{
1616
int experimental;
1717
int value;
18-
char *strval;
18+
const char *strval;
1919
int manyfiles;
2020

2121
if (!r->gitdir)
@@ -67,7 +67,7 @@ void prepare_repo_settings(struct repository *r)
6767
if (!repo_config_get_int(r, "index.version", &value))
6868
r->settings.index_version = value;
6969

70-
if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
70+
if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) {
7171
int v = git_parse_maybe_bool(strval);
7272

7373
/*
@@ -78,10 +78,9 @@ void prepare_repo_settings(struct repository *r)
7878
if (v >= 0)
7979
r->settings.core_untracked_cache = v ?
8080
UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE;
81-
free(strval);
8281
}
8382

84-
if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
83+
if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) {
8584
int fetch_default = r->settings.fetch_negotiation_algorithm;
8685
if (!strcasecmp(strval, "skipping"))
8786
r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;

transport.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ static int fetch_refs_via_pack(struct transport *transport,
386386
args.cloning = transport->cloning;
387387
args.update_shallow = data->options.update_shallow;
388388
args.from_promisor = data->options.from_promisor;
389-
args.filter_options = data->options.filter_options;
389+
list_objects_filter_copy(&args.filter_options,
390+
&data->options.filter_options);
390391
args.refetch = data->options.refetch;
391392
args.stateless_rpc = transport->stateless_rpc;
392393
args.server_options = transport->server_options;
@@ -453,6 +454,7 @@ static int fetch_refs_via_pack(struct transport *transport,
453454

454455
free_refs(refs_tmp);
455456
free_refs(refs);
457+
list_objects_filter_release(&args.filter_options);
456458
return ret;
457459
}
458460

@@ -893,6 +895,7 @@ static int disconnect_git(struct transport *transport)
893895
finish_connect(data->conn);
894896
}
895897

898+
list_objects_filter_release(&data->options.filter_options);
896899
free(data);
897900
return 0;
898901
}

0 commit comments

Comments
 (0)