diff options
author | Patrick Steinhardt <ps@pks.im> | 2020-08-24 11:20:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-24 11:20:50 +0200 |
commit | da3288ded5bce2a37566126be51fe75ff0316c2d (patch) | |
tree | a99ad9ec4819760153fe9c183231884e3d18b8ab | |
parent | 24eacab96b68543b377ff91c61ee9c2700303c43 (diff) | |
parent | 04d59466238e69c57d2a82d0693a77ecb05e1194 (diff) | |
download | libgit2-da3288ded5bce2a37566126be51fe75ff0316c2d.tar.gz |
Merge pull request #5600 from andrewhickman/fix-double-free
Fix `git_mwindow_scan_recently_used` spuriously returning true
-rw-r--r-- | src/mwindow.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/mwindow.c b/src/mwindow.c index c257f0c71..ac26452f4 100644 --- a/src/mwindow.c +++ b/src/mwindow.c @@ -184,7 +184,8 @@ int git_mwindow_contains(git_mwindow *win, off64_t offset) /* * Find the least- or most-recently-used window in a file that is not currently * being used. The 'only_unused' flag controls whether the caller requires the - * file to only have unused windows. + * file to only have unused windows. If '*out_window' is non-null, it is used as + * a starting point for the comparison. * * Returns whether such a window was found in the file. */ @@ -197,6 +198,7 @@ static bool git_mwindow_scan_recently_used( { git_mwindow *w, *w_last; git_mwindow *lru_window = NULL, *lru_last = NULL; + bool found = false; assert(mwf); assert(out_window); @@ -223,10 +225,11 @@ static bool git_mwindow_scan_recently_used( (comparison_sign == GIT_MWINDOW__MRU && lru_window->last_used < w->last_used)) { lru_window = w; lru_last = w_last; + found = true; } } - if (!lru_window && !lru_last) + if (!found) return false; *out_window = lru_window; |