pickaxe: plug regex leak

With -G... --pickaxe-all, free the regex before returning even if we found a match. Also get rid of the variable has_changes, as we can simply break out of the loop. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 6, 2011 at 18:14 UTC 2b5f07f16c9e554482ed4a2355a051feabd62848
1 file changed +6 -7
diffcore-pickaxe.c
+6 -7
@@ -96,7 +96,7 @@ static int diff_grep(struct diff_filepair *p, regex_t *regexp, struct diff_optio
96 static void diffcore_pickaxe_grep(struct diff_options *o)
97 {
98 struct diff_queue_struct *q = &diff_queued_diff;
99 - int i, has_changes, err;
99 + int i, err;
100 regex_t regex;
101 struct diff_queue_struct outq;
102 outq.queue = NULL;
@@ -112,13 +112,11 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
112
113 if (o->pickaxe_opts & DIFF_PICKAXE_ALL) {
114 /* Showing the whole changeset if needle exists */
115 - for (i = has_changes = 0; !has_changes && i < q->nr; i++) {
115 + for (i = 0; i < q->nr; i++) {
116 struct diff_filepair *p = q->queue[i];
117 if (diff_grep(p, &regex, o))
118 - has_changes++;
118 + goto out; /* do not munge the queue */
119 }
120 - if (has_changes)
121 - return; /* do not munge the queue */
120
121 /*
122 * Otherwise we will clear the whole queue by copying
@@ -138,10 +136,11 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
136 }
137 }
138
141 - regfree(&regex);
142 -
139 free(q->queue);
140 *q = outq;
141 +
142 + out:
143 + regfree(&regex);
144 return;
145 }
146