Skip to content

Commit 6610669

Browse files
committed
Merge branch 'sb/misc-cleanups' into HEAD
* sb/misc-cleanups: submodule-config: don't shadow `cache` config.c: drop local variable credential-cache, send_request: close fd when done bundle: don't leak an fd in case of early return abbrev_sha1_in_line: don't leak memory notes: don't leak memory in git_config_get_notes_strategy
2 parents 989cbd4 + 99dab16 commit 6610669

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

builtin/notes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,14 @@ static int merge_commit(struct notes_merge_options *o)
744744
static int git_config_get_notes_strategy(const char *key,
745745
enum notes_merge_strategy *strategy)
746746
{
747-
const char *value;
747+
char *value;
748748

749-
if (git_config_get_string_const(key, &value))
749+
if (git_config_get_string(key, &value))
750750
return 1;
751751
if (parse_notes_merge_strategy(value, strategy))
752752
git_die_config(key, "unknown notes merge strategy %s", value);
753753

754+
free(value);
754755
return 0;
755756
}
756757

bundle.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,30 +435,41 @@ int create_bundle(struct bundle_header *header, const char *path,
435435

436436
/* write prerequisites */
437437
if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
438-
return -1;
438+
goto err;
439439

440440
argc = setup_revisions(argc, argv, &revs, NULL);
441441

442-
if (argc > 1)
443-
return error(_("unrecognized argument: %s"), argv[1]);
442+
if (argc > 1) {
443+
error(_("unrecognized argument: %s"), argv[1]);
444+
goto err;
445+
}
444446

445447
object_array_remove_duplicates(&revs.pending);
446448

447449
ref_count = write_bundle_refs(bundle_fd, &revs);
448450
if (!ref_count)
449451
die(_("Refusing to create empty bundle."));
450452
else if (ref_count < 0)
451-
return -1;
453+
goto err;
452454

453455
/* write pack */
454-
if (write_pack_data(bundle_fd, &revs))
455-
return -1;
456+
if (write_pack_data(bundle_fd, &revs)) {
457+
bundle_fd = -1; /* already closed by the above call */
458+
goto err;
459+
}
456460

457461
if (!bundle_to_stdout) {
458462
if (commit_lock_file(&lock))
459463
die_errno(_("cannot create '%s'"), path);
460464
}
461465
return 0;
466+
err:
467+
if (!bundle_to_stdout) {
468+
if (0 <= bundle_fd)
469+
close(bundle_fd);
470+
rollback_lock_file(&lock);
471+
}
472+
return -1;
462473
}
463474

464475
int unbundle(struct bundle_header *header, int bundle_fd, int flags)

config.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,14 +1309,11 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
13091309
struct config_set_element k;
13101310
struct config_set_element *found_entry;
13111311
char *normalized_key;
1312-
int ret;
13131312
/*
13141313
* `key` may come from the user, so normalize it before using it
13151314
* for querying entries from the hashmap.
13161315
*/
1317-
ret = git_config_parse_key(key, &normalized_key, NULL);
1318-
1319-
if (ret)
1316+
if (git_config_parse_key(key, &normalized_key, NULL))
13201317
return NULL;
13211318

13221319
hashmap_entry_init(&k, strhash(normalized_key));

credential-cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ static int send_request(const char *socket, const struct strbuf *out)
3232
write_or_die(1, in, r);
3333
got_data = 1;
3434
}
35+
close(fd);
3536
return got_data;
3637
}
3738

submodule-config.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum lookup_type {
3030
lookup_path
3131
};
3232

33-
static struct submodule_cache cache;
33+
static struct submodule_cache the_submodule_cache;
3434
static int is_cache_init;
3535

3636
static int config_path_cmp(const struct submodule_entry *a,
@@ -457,14 +457,14 @@ static void ensure_cache_init(void)
457457
if (is_cache_init)
458458
return;
459459

460-
cache_init(&cache);
460+
cache_init(&the_submodule_cache);
461461
is_cache_init = 1;
462462
}
463463

464464
int parse_submodule_config_option(const char *var, const char *value)
465465
{
466466
struct parse_config_parameter parameter;
467-
parameter.cache = &cache;
467+
parameter.cache = &the_submodule_cache;
468468
parameter.commit_sha1 = NULL;
469469
parameter.gitmodules_sha1 = null_sha1;
470470
parameter.overwrite = 1;
@@ -477,18 +477,18 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
477477
const char *name)
478478
{
479479
ensure_cache_init();
480-
return config_from_name(&cache, commit_sha1, name);
480+
return config_from_name(&the_submodule_cache, commit_sha1, name);
481481
}
482482

483483
const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
484484
const char *path)
485485
{
486486
ensure_cache_init();
487-
return config_from_path(&cache, commit_sha1, path);
487+
return config_from_path(&the_submodule_cache, commit_sha1, path);
488488
}
489489

490490
void submodule_free(void)
491491
{
492-
cache_free(&cache);
492+
cache_free(&the_submodule_cache);
493493
is_cache_init = 0;
494494
}

wt-status.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,7 @@ static void abbrev_sha1_in_line(struct strbuf *line)
10631063
strbuf_addf(line, "%s", split[i]->buf);
10641064
}
10651065
}
1066-
for (i = 0; split[i]; i++)
1067-
strbuf_release(split[i]);
1068-
1066+
strbuf_list_free(split);
10691067
}
10701068

10711069
static void read_rebase_todolist(const char *fname, struct string_list *lines)

0 commit comments

Comments
 (0)