Skip to content

Commit fc452ae

Browse files
committed
Merge branch 'sb/misc-cleanups'
Assorted minor clean-ups. * sb/misc-cleanups: 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 5250af4 + 9c60d9f commit fc452ae

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
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)

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

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)