From 069ee112153031d7a15b4d07f2aee2c6649a8697 Mon Sep 17 00:00:00 2001 From: Andy Maloney Date: Fri, 2 Oct 2020 09:35:42 -0400 Subject: [PATCH] String: Fix "Use of memory after it is freed" when assigning to self destruct() can call delete[], but then we use the memory in operator=. Found using clang static analysis. --- src/Corrade/Containers/String.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Corrade/Containers/String.cpp b/src/Corrade/Containers/String.cpp index f78de84c7..e8e0319e9 100644 --- a/src/Corrade/Containers/String.cpp +++ b/src/Corrade/Containers/String.cpp @@ -189,6 +189,8 @@ String::String(String&& other) noexcept { } String& String::operator=(const String& other) { + if(other == *this) return *this; + destruct(); const std::pair data = other.dataInternal();