Message ID | cf6bcdb43e5b4abab464c30a914d64dc8e7a9925.1655336146.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Coverity fixes | expand |
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > 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; > } Hmph. Without the "lets make sure we do not leak in the error code path", it would have been no brainer to avoid this bug in the original version. Of course the postimage of the above hunk is correct, but with extra free() sprinkled, it became ugly to the eye. I wonder if the following is easier to follow. Thanks. object-name.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git c/object-name.c w/object-name.c index 4d2746574c..57188db7b0 100644 --- c/object-name.c +++ w/object-name.c @@ -1971,13 +1971,16 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, memcmp(ce->name, cp, namelen)) break; if (ce_stage(ce) == stage) { + int ret = -1; + + if (!reject_tree_in_index(repo, only_to_die, ce, + stage, prefix, cp)) { + oidcpy(oid, &ce->oid); + oc->mode = ce->ce_mode; + ret = 0; + } free(new_path); - if (reject_tree_in_index(repo, only_to_die, ce, - stage, prefix, cp)) - return -1; - oidcpy(oid, &ce->oid); - oc->mode = ce->ce_mode; - return 0; + return ret; } pos++; }
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++;