pickaxe: plug regex/kws leak

With -S... --pickaxe-all, free the regex or the kws 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:23 UTC 8e854b00d86070dd463a91bdbc401fb25dc9ddb5
1 file changed +7 -6
diffcore-pickaxe.c
+7 -6
@@ -221,7 +221,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
221
222 if (opts & DIFF_PICKAXE_ALL) {
223 /* Showing the whole changeset if needle exists */
224 - for (i = has_changes = 0; !has_changes && i < q->nr; i++) {
224 + for (i = 0; i < q->nr; i++) {
225 struct diff_filepair *p = q->queue[i];
226 if (!DIFF_FILE_VALID(p->one)) {
227 if (!DIFF_FILE_VALID(p->two))
@@ -238,9 +238,9 @@ static void diffcore_pickaxe_count(struct diff_options *o)
238 contains(p->one, needle, len, regexp, kws) !=
239 contains(p->two, needle, len, regexp, kws))
240 has_changes++;
241 + if (has_changes)
242 + goto out; /* do not munge the queue */
243 }
242 - if (has_changes)
243 - return; /* not munge the queue */
244
245 /* otherwise we will clear the whole queue
246 * by copying the empty outq at the end of this
@@ -278,13 +278,14 @@ static void diffcore_pickaxe_count(struct diff_options *o)
278 diff_free_filepair(p);
279 }
280
281 + free(q->queue);
282 + *q = outq;
283 +
284 + out:
285 if (opts & DIFF_PICKAXE_REGEX)
286 regfree(&regex);
287 else
288 kwsfree(kws);
285 -
286 - free(q->queue);
287 - *q = outq;
289 return;
290 }
291