summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar René Scharfe <rene.scharfe@lsrfire.ath.cx>2011-10-06 18:23:11 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2011-10-07 15:46:13 -0700
commit8e854b00d86070dd463a91bdbc401fb25dc9ddb5 (patch)
tree66ed8f16c98fae281afebc77c05e3f6f148c8e28
parentpickaxe: plug regex leak (diff)
downloadtgif-8e854b00d86070dd463a91bdbc401fb25dc9ddb5.tar.xz
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>
-rw-r--r--diffcore-pickaxe.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 96f7ea67da..c367d8d17a 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -221,7 +221,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
if (opts & DIFF_PICKAXE_ALL) {
/* Showing the whole changeset if needle exists */
- for (i = has_changes = 0; !has_changes && i < q->nr; i++) {
+ for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (!DIFF_FILE_VALID(p->one)) {
if (!DIFF_FILE_VALID(p->two))
@@ -238,9 +238,9 @@ static void diffcore_pickaxe_count(struct diff_options *o)
contains(p->one, needle, len, regexp, kws) !=
contains(p->two, needle, len, regexp, kws))
has_changes++;
+ if (has_changes)
+ goto out; /* do not munge the queue */
}
- if (has_changes)
- return; /* not munge the queue */
/* otherwise we will clear the whole queue
* by copying the empty outq at the end of this
@@ -278,13 +278,14 @@ static void diffcore_pickaxe_count(struct diff_options *o)
diff_free_filepair(p);
}
+ free(q->queue);
+ *q = outq;
+
+ out:
if (opts & DIFF_PICKAXE_REGEX)
regfree(&regex);
else
kwsfree(kws);
-
- free(q->queue);
- *q = outq;
return;
}