From: Johannes Schindelin <johannes.schindelin@xxxxxx> In 561287d342cc (object-name: reject trees found in the index, 2022-04-26), we changed the code to release the memory stored under the `new_path` variable a bit earlier. However, at that point the variable `cp` still points to `new_path` (if non-`NULL`), and we _then_ pass that pointer to `reject_tree_in_index()`. Let's make sure that the pointer still points to allocated memory by moving the original `free()` call back where it was, and adding another one in the early return code path. Reported by Coverity. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- object-name.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/object-name.c b/object-name.c index 4d2746574cd..228c12a554c 100644 --- a/object-name.c +++ b/object-name.c @@ -1971,12 +1971,14 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, memcmp(ce->name, cp, namelen)) break; if (ce_stage(ce) == stage) { - free(new_path); if (reject_tree_in_index(repo, only_to_die, ce, - stage, prefix, cp)) + stage, prefix, cp)) { + free(new_path); return -1; + } oidcpy(oid, &ce->oid); oc->mode = ce->ce_mode; + free(new_path); return 0; } pos++; -- gitgitgadget