Skip to content

Commit 8e854b0

Browse files
René Scharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b5f07f commit 8e854b0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

diffcore-pickaxe.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
221221

222222
if (opts & DIFF_PICKAXE_ALL) {
223223
/* 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++) {
225225
struct diff_filepair *p = q->queue[i];
226226
if (!DIFF_FILE_VALID(p->one)) {
227227
if (!DIFF_FILE_VALID(p->two))
@@ -238,9 +238,9 @@ static void diffcore_pickaxe_count(struct diff_options *o)
238238
contains(p->one, needle, len, regexp, kws) !=
239239
contains(p->two, needle, len, regexp, kws))
240240
has_changes++;
241+
if (has_changes)
242+
goto out; /* do not munge the queue */
241243
}
242-
if (has_changes)
243-
return; /* not munge the queue */
244244

245245
/* otherwise we will clear the whole queue
246246
* by copying the empty outq at the end of this
@@ -278,13 +278,14 @@ static void diffcore_pickaxe_count(struct diff_options *o)
278278
diff_free_filepair(p);
279279
}
280280

281+
free(q->queue);
282+
*q = outq;
283+
284+
out:
281285
if (opts & DIFF_PICKAXE_REGEX)
282286
regfree(&regex);
283287
else
284288
kwsfree(kws);
285-
286-
free(q->queue);
287-
*q = outq;
288289
return;
289290
}
290291

0 commit comments

Comments
 (0)