pack-write: fix return parameter of write_rev_file_order()
While the return parameter of `write_rev_file_order()` is a string constant, the function may indeed return an allocated string when its first parameter is a `NULL` pointer. This makes for a confusing calling convention, where callers need to be aware of these intricate ownership rules and cast away the constness to free the string in some cases. Adapt the function and its caller `write_rev_file()` to always return an allocated string and adapt callers to always free the return value. Note that this requires us to also adapt `rename_tmp_packfile()`, which compares the pointers to packfile data with each other. Now that the path of the reverse index file gets allocated unconditionally the check will always fail. This is fixed by using strcmp(3P) instead, which also feels way less fragile. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
6512d6e473
commit
2f0ee051dd
@ -1505,7 +1505,7 @@ static void rename_tmp_packfile(const char **final_name,
|
||||
struct strbuf *name, unsigned char *hash,
|
||||
const char *ext, int make_read_only_if_same)
|
||||
{
|
||||
if (*final_name != curr_name) {
|
||||
if (!*final_name || strcmp(*final_name, curr_name)) {
|
||||
if (!*final_name)
|
||||
*final_name = odb_pack_name(name, hash, ext);
|
||||
if (finalize_object_file(curr_name, *final_name))
|
||||
@ -1726,7 +1726,7 @@ int cmd_index_pack(int argc,
|
||||
{
|
||||
int i, fix_thin_pack = 0, verify = 0, stat_only = 0, rev_index;
|
||||
const char *curr_index;
|
||||
const char *curr_rev_index = NULL;
|
||||
char *curr_rev_index = NULL;
|
||||
const char *index_name = NULL, *pack_name = NULL, *rev_index_name = NULL;
|
||||
const char *keep_msg = NULL;
|
||||
const char *promisor_msg = NULL;
|
||||
@ -1968,8 +1968,7 @@ int cmd_index_pack(int argc,
|
||||
free((void *) curr_pack);
|
||||
if (!index_name)
|
||||
free((void *) curr_index);
|
||||
if (!rev_index_name)
|
||||
free((void *) curr_rev_index);
|
||||
free(curr_rev_index);
|
||||
|
||||
/*
|
||||
* Let the caller know this pack is not self contained
|
||||
|
Reference in New Issue
Block a user