From beeab28e786f368d8c43790463a781b7aa026d90 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 3 Nov 2019 17:56:45 +0000 Subject: [PATCH] Fix 66b32df7: Use after free in GRFFileScanner::AddFile --- src/newgrf_config.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp index 0c8d8ed014..5653efeb4f 100644 --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -781,10 +781,6 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const bool added = FillGRFDetails(c, false); if (added) { this->grfs.push_back(c); - } else { - /* File couldn't be opened, or is either not a NewGRF or is a - * 'system' NewGRF or it's already known, so forget about it. */ - delete c; } this->num_scanned++; @@ -803,6 +799,12 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const this->next_update = _realtime_tick + MODAL_PROGRESS_REDRAW_TIMEOUT; } + if (!added) { + /* File couldn't be opened, or is either not a NewGRF or is a + * 'system' NewGRF or it's already known, so forget about it. */ + delete c; + } + return added; }