From: Hiltjo Posthuma Date: Sat, 22 Apr 2017 17:07:07 +0000 (+0200) Subject: improve commitinfo_getstats X-Git-Url: https://git.armaanb.net/?p=stagit.git;a=commitdiff_plain;h=8fa0effa9846a18a60d3b6a7c96db42a2775a7c6 improve commitinfo_getstats - reorder: unnecessary allocation when git_patch_from_diff fails. - no need to free patch object when git_patch_from_diff fails. --- diff --git a/stagit.c b/stagit.c index f280542..5eb5f1c 100644 --- a/stagit.c +++ b/stagit.c @@ -110,13 +110,10 @@ commitinfo_getstats(struct commitinfo *ci) err(1, "calloc"); for (i = 0; i < ndeltas; i++) { + if (git_patch_from_diff(&patch, ci->diff, i)) + goto err; if (!(di = calloc(1, sizeof(struct deltainfo)))) err(1, "calloc"); - if (git_patch_from_diff(&patch, ci->diff, i)) { - git_patch_free(patch); - free(di); - goto err; - } di->patch = patch; ci->deltas[i] = di;