Skip to content

Commit c412583

Browse files
ttaylorrgitster
authored andcommitted
pack-write.c: plug a leak in stage_tmp_packfiles()
The function `stage_tmp_packfiles()` generates a filename to use for staging the contents of what will become the pack's ".mtimes" file. The name is generated in `write_mtimes_file()` and the result is returned back to `stage_tmp_packfiles()` which uses it to rename the temporary file into place via `rename_tmp_packfiles()`. `write_mtimes_file()` returns a `const char *`, indicating that callers are not expected to free its result (similar to, e.g., `oid_to_hex()`). But callers are expected to free its result, so this return type is incorrect. Change the function's signature to return a non-const `char *`, and free it at the end of `stage_tmp_packfiles()`. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9857273 commit c412583

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pack-write.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,13 @@ static void write_mtimes_trailer(struct hashfile *f, const unsigned char *hash)
312312
hashwrite(f, hash, the_hash_algo->rawsz);
313313
}
314314

315-
static const char *write_mtimes_file(struct packing_data *to_pack,
316-
struct pack_idx_entry **objects,
317-
uint32_t nr_objects,
318-
const unsigned char *hash)
315+
static char *write_mtimes_file(struct packing_data *to_pack,
316+
struct pack_idx_entry **objects,
317+
uint32_t nr_objects,
318+
const unsigned char *hash)
319319
{
320320
struct strbuf tmp_file = STRBUF_INIT;
321-
const char *mtimes_name;
321+
char *mtimes_name;
322322
struct hashfile *f;
323323
int fd;
324324

@@ -544,7 +544,7 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
544544
char **idx_tmp_name)
545545
{
546546
const char *rev_tmp_name = NULL;
547-
const char *mtimes_tmp_name = NULL;
547+
char *mtimes_tmp_name = NULL;
548548

549549
if (adjust_shared_perm(pack_tmp_name))
550550
die_errno("unable to make temporary pack file readable");
@@ -568,6 +568,8 @@ void stage_tmp_packfiles(struct strbuf *name_buffer,
568568
rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
569569
if (mtimes_tmp_name)
570570
rename_tmp_packfile(name_buffer, mtimes_tmp_name, "mtimes");
571+
572+
free(mtimes_tmp_name);
571573
}
572574

573575
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)

0 commit comments

Comments
 (0)