From 0f2855ada8dcd4cdce81fe3f6b8234cf9ad51439 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 26 May 2021 20:43:03 -0700 Subject: [PATCH] mem: fix rare crash/logic error in heap allocation code --- .../source/mem/impl/heap/mem_impl_heap_tls_heap_central.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.cpp b/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.cpp index 136677dec..681f62678 100644 --- a/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.cpp +++ b/libraries/libstratosphere/source/mem/impl/heap/mem_impl_heap_tls_heap_central.cpp @@ -976,13 +976,14 @@ namespace ams::mem::impl::heap { return span; } } else { + const size_t prev_pages = span->num_pages; + Span *new_span = this->AllocateSpanStruct(); if (new_span == nullptr) { return nullptr; } auto new_span_guard = SCOPE_GUARD { this->FreeSpanToSpanPage(new_span); }; - const size_t prev_pages = span->num_pages; span = GetSpanFromPointer(std::addressof(this->span_table), span->start.p); const size_t found_pages = span->num_pages;