Skip to content

Commit fffe7d8

Browse files
rscharfegitster
authored andcommitted
diff-no-index: release strbuf on queue error
The strbuf is small and we are about to exit, so we could leave its cleanup to the OS. If we release it explicitly at all, however, then we should do it on early exit as well. Move the strbuf_release call to a new cleanup section at the end and make sure all execution paths go through it. Suggested-by: Johannes Schindelin <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ac8035a commit fffe7d8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

diff-no-index.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ int diff_no_index(struct rev_info *revs,
243243
int argc, const char **argv)
244244
{
245245
int i, no_index;
246+
int ret = 1;
246247
const char *paths[2];
247248
struct strbuf replacement = STRBUF_INIT;
248249
const char *prefix = revs->prefix;
@@ -295,16 +296,18 @@ int diff_no_index(struct rev_info *revs,
295296
revs->diffopt.flags.exit_with_status = 1;
296297

297298
if (queue_diff(&revs->diffopt, paths[0], paths[1]))
298-
return 1;
299+
goto out;
299300
diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
300301
diffcore_std(&revs->diffopt);
301302
diff_flush(&revs->diffopt);
302303

303-
strbuf_release(&replacement);
304-
305304
/*
306305
* The return code for --no-index imitates diff(1):
307306
* 0 = no changes, 1 = changes, else error
308307
*/
309-
return diff_result_code(&revs->diffopt, 0);
308+
ret = diff_result_code(&revs->diffopt, 0);
309+
310+
out:
311+
strbuf_release(&replacement);
312+
return ret;
310313
}

0 commit comments

Comments
 (0)