diff options
author | Taylor Blau <me@ttaylorr.com> | 2021-10-26 17:01:21 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-28 15:32:14 -0700 |
commit | 60980aed786487e9113f0cb2907dfc75a77d363c (patch) | |
tree | 1fcd95354a08daa38ab957f5f81c3409e371a250 /dir-iterator.h | |
parent | builtin/multi-pack-index.c: don't leak concatenated options (diff) | |
download | tgif-60980aed786487e9113f0cb2907dfc75a77d363c.tar.xz |
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 'dir-iterator.h')
0 files changed, 0 insertions, 0 deletions