From c56810e6a51971b84f60dc4b4a27e15a95f047f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Tue, 21 Sep 2021 01:34:58 -0700 Subject: [PATCH] Fix #15442: Use after free in object manager --- src/openrct2/Editor.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index d72df4dd1c..37ec3865ee 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -63,15 +63,18 @@ namespace Editor static void object_list_load() { + auto* context = GetContext(); + + // Unload objects first, the repository is re-populated which owns the objects. + auto& objectManager = context->GetObjectManager(); + objectManager.UnloadAll(); + // Scan objects if necessary - auto context = GetContext(); const auto& localisationService = context->GetLocalisationService(); auto& objectRepository = context->GetObjectRepository(); objectRepository.LoadOrConstruct(localisationService.GetCurrentLanguage()); // Reset loaded objects to just defaults - auto& objectManager = context->GetObjectManager(); - objectManager.UnloadAll(); objectManager.LoadDefaultObjects(); }