summaryrefslogtreecommitdiff
path: root/pack-revindex.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2021-10-26 21:01:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-10-28 22:32:14 (GMT)
commit60980aed786487e9113f0cb2907dfc75a77d363c (patch)
tree1fcd95354a08daa38ab957f5f81c3409e371a250 /pack-revindex.c
parentee4a1d63d7e9bdbea6bbeeb3f82ef33030de9ffb (diff)
downloadgit-60980aed786487e9113f0cb2907dfc75a77d363c.zip
git-60980aed786487e9113f0cb2907dfc75a77d363c.tar.gz
git-60980aed786487e9113f0cb2907dfc75a77d363c.tar.bz2
midx.c: write MIDX filenames to strbuf
To ask for the name of a MIDX and its corresponding .rev file, callers invoke get_midx_filename() and get_midx_rev_filename(), respectively. These both invoke xstrfmt(), allocating a chunk of memory which must be freed later on. This makes callers in pack-bitmap.c somewhat awkward. Specifically, midx_bitmap_filename(), which is implemented like: return xstrfmt("%s-%s.bitmap", get_midx_filename(midx->object_dir), hash_to_hex(get_midx_checksum(midx))); this leaks the second argument to xstrfmt(), which itself was allocated with xstrfmt(). This caller could assign both the result of get_midx_filename() and the outer xstrfmt() to a temporary variable, remembering to free() the former before returning. But that involves a wasteful copy. Instead, get_midx_filename() and get_midx_rev_filename() take a strbuf as an output parameter. This way midx_bitmap_filename() can manipulate and pass around a temporary buffer which it detaches back to its caller. That allows us to implement the function without copying or open-coding get_midx_filename() in a way that doesn't leak. Update the other callers of get_midx_filename() and get_midx_rev_filename() accordingly. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-revindex.c')
-rw-r--r--pack-revindex.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/pack-revindex.c b/pack-revindex.c
index 0e4a31d..70d0fba 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -296,14 +296,14 @@ int load_pack_revindex(struct packed_git *p)
int load_midx_revindex(struct multi_pack_index *m)
{
- char *revindex_name;
+ struct strbuf revindex_name = STRBUF_INIT;
int ret;
if (m->revindex_data)
return 0;
- revindex_name = get_midx_rev_filename(m);
+ get_midx_rev_filename(&revindex_name, m);
- ret = load_revindex_from_disk(revindex_name,
+ ret = load_revindex_from_disk(revindex_name.buf,
m->num_objects,
&m->revindex_map,
&m->revindex_len);
@@ -313,7 +313,7 @@ int load_midx_revindex(struct multi_pack_index *m)
m->revindex_data = (const uint32_t *)((const char *)m->revindex_map + RIDX_HEADER_SIZE);
cleanup:
- free(revindex_name);
+ strbuf_release(&revindex_name);
return ret;
}