From 006d1000c76ca383950c439fde2b5696425ba468 Mon Sep 17 00:00:00 2001 From: dongresource Date: Thu, 24 Sep 2020 03:12:24 +0200 Subject: [PATCH] Add Address Sanitizer suppression list. This replaces the unnecessary deallocations on program termination. Passing in the suppression list environment variable via setenv() doesn't seem to work, so I've added a comment in the Makefile to explain invocation. --- Makefile | 1 + src/ChunkManager.cpp | 6 ------ src/TableData.cpp | 13 ------------- src/main.cpp | 3 --- suppr.txt | 4 ++++ 5 files changed, 5 insertions(+), 22 deletions(-) create mode 100644 suppr.txt diff --git a/Makefile b/Makefile index f906514..d78f770 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ CC=clang CXX=clang++ # -w suppresses all warnings (the part that's commented out helps me find memory leaks, it ruins performance though!) +# If compiling with ASAN, invoke like this: $ LSAN_OPTIONS=suppressions=suppr.txt bin/fusion CFLAGS=-O3 #-g3 -fsanitize=address CXXFLAGS=-Wall -Wno-unknown-pragmas -std=c++17 -O2 -DPROTOCOL_VERSION=$(PROTOCOL_VERSION) -DGIT_VERSION=\"$(shell git describe --tags)\" #-g3 -fsanitize=address LDFLAGS=-lpthread -ldl #-g3 -fsanitize=address diff --git a/src/ChunkManager.cpp b/src/ChunkManager.cpp index dcb9a1e..e130461 100644 --- a/src/ChunkManager.cpp +++ b/src/ChunkManager.cpp @@ -6,12 +6,6 @@ std::map, Chunk*> ChunkManager::chunks; void ChunkManager::init() {} // stubbed -void ChunkManager::cleanup() { - // cleans up all the allocated chunks - for (auto& pair : chunks) { - delete pair.second; - } -} void ChunkManager::addNPC(int posX, int posY, int32_t id) { std::pair pos = grabChunk(posX, posY); diff --git a/src/TableData.cpp b/src/TableData.cpp index f1a5312..e4cf50b 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -189,19 +189,6 @@ void TableData::init() { } } -void TableData::cleanup() { - /* - * This is just to shut the address sanitizer up. Dynamically allocated data - * doesn't need to be cleaned up if it's supposed to last the program's full runtime. - */ - for (auto& pair : MissionManager::Rewards) - delete pair.second; - for (auto& pair : MissionManager::Tasks) - delete pair.second; - for (auto& pair : NPCManager::NPCs) - delete pair.second; -} - /* * Some item categories either don't possess iEquipLoc or use a different value for item type. */ diff --git a/src/main.cpp b/src/main.cpp index d26750d..1674e20 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,9 +49,6 @@ void terminate(int arg) { shardThread->join(); } - TableData::cleanup(); - ChunkManager::cleanup(); - exit(0); } diff --git a/suppr.txt b/suppr.txt new file mode 100644 index 0000000..14d8a4e --- /dev/null +++ b/suppr.txt @@ -0,0 +1,4 @@ +leak:TableData::init +leak:ChunkManager::addPlayer +leak:ChunkManager::addNPC +leak:nlohmann::basic_json