Skip to content

Commit da3288d

Browse files
authored
Merge pull request libgit2#5600 from andrewhickman/fix-double-free
Fix `git_mwindow_scan_recently_used` spuriously returning true
2 parents 24eacab + 04d5946 commit da3288d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/mwindow.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ int git_mwindow_contains(git_mwindow *win, off64_t offset)
184184
/*
185185
* Find the least- or most-recently-used window in a file that is not currently
186186
* being used. The 'only_unused' flag controls whether the caller requires the
187-
* file to only have unused windows.
187+
* file to only have unused windows. If '*out_window' is non-null, it is used as
188+
* a starting point for the comparison.
188189
*
189190
* Returns whether such a window was found in the file.
190191
*/
@@ -197,6 +198,7 @@ static bool git_mwindow_scan_recently_used(
197198
{
198199
git_mwindow *w, *w_last;
199200
git_mwindow *lru_window = NULL, *lru_last = NULL;
201+
bool found = false;
200202

201203
assert(mwf);
202204
assert(out_window);
@@ -223,10 +225,11 @@ static bool git_mwindow_scan_recently_used(
223225
(comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) {
224226
lru_window = w;
225227
lru_last = w_last;
228+
found = true;
226229
}
227230
}
228231

229-
if (!lru_window && !lru_last)
232+
if (!found)
230233
return false;
231234

232235
*out_window = lru_window;

0 commit comments

Comments
 (0)