Skip to content

Commit c81dcf6

Browse files
pks-tgitster
authored andcommitted
bulk-checkin: fix leaking state TODO
When flushing a bulk-checking to disk we also reset the `struct bulk_checkin_packfile` state. But while we free some of its members, others aren't being free'd, leading to memory leaks: - The temporary packfile name is not getting freed. - The `struct hashfile` only gets freed in case we end up calling `finalize_hashfile()`. There are code paths though where that is not the case, namely when nothing has been written. For this, we need to make `free_hashfile()` public. Fix those leaks. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ddd5f7 commit c81dcf6

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

bulk-checkin.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
6161

6262
if (state->nr_written == 0) {
6363
close(state->f->fd);
64+
free_hashfile(state->f);
6465
unlink(state->pack_tmp_name);
6566
goto clear_exit;
6667
} else if (state->nr_written == 1) {
@@ -83,6 +84,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
8384
free(state->written[i]);
8485

8586
clear_exit:
87+
free(state->pack_tmp_name);
8688
free(state->written);
8789
memset(state, 0, sizeof(*state));
8890

csum-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void hashflush(struct hashfile *f)
5656
}
5757
}
5858

59-
static void free_hashfile(struct hashfile *f)
59+
void free_hashfile(struct hashfile *f)
6060
{
6161
free(f->buffer);
6262
free(f->check_buffer);

csum-file.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
4646
struct hashfile *hashfd(int fd, const char *name);
4747
struct hashfile *hashfd_check(const char *name);
4848
struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
49+
50+
/*
51+
* Free the hashfile without flushing its contents to disk. This only
52+
* needs to be called when not calling `finalize_hashfile()`.
53+
*/
54+
void free_hashfile(struct hashfile *f);
55+
56+
/*
57+
* Finalize the hashfile by flushing data to disk and free'ing it.
58+
*/
4959
int finalize_hashfile(struct hashfile *, unsigned char *, enum fsync_component, unsigned int);
5060
void hashwrite(struct hashfile *, const void *, unsigned int);
5161
void hashflush(struct hashfile *f);

t/t1050-large.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
test_description='adding and checking out large blobs'
55

6+
TEST_PASSES_SANITIZE_LEAK=true
67
. ./test-lib.sh
78

89
test_expect_success 'core.bigFileThreshold must be non-negative' '

0 commit comments

Comments
 (0)