Skip to content

Commit 2b5f07f

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

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

diffcore-pickaxe.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static int diff_grep(struct diff_filepair *p, regex_t *regexp, struct diff_optio
9696
static void diffcore_pickaxe_grep(struct diff_options *o)
9797
{
9898
struct diff_queue_struct *q = &diff_queued_diff;
99-
int i, has_changes, err;
99+
int i, err;
100100
regex_t regex;
101101
struct diff_queue_struct outq;
102102
outq.queue = NULL;
@@ -112,13 +112,11 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
112112

113113
if (o->pickaxe_opts & DIFF_PICKAXE_ALL) {
114114
/* 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++) {
116116
struct diff_filepair *p = q->queue[i];
117117
if (diff_grep(p, &regex, o))
118-
has_changes++;
118+
goto out; /* do not munge the queue */
119119
}
120-
if (has_changes)
121-
return; /* do not munge the queue */
122120

123121
/*
124122
* Otherwise we will clear the whole queue by copying
@@ -138,10 +136,11 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
138136
}
139137
}
140138

141-
regfree(&regex);
142-
143139
free(q->queue);
144140
*q = outq;
141+
142+
out:
143+
regfree(&regex);
145144
return;
146145
}
147146

0 commit comments

Comments
 (0)