From c2926f2a0d70fa7287214c05e3787b5b6cda95c6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 27 Sep 2017 02:36:14 +0200 Subject: [PATCH] Store custom strings as const char*, not std::string. It would seem that std::string is not moved, but copied, thus invalidating the pointer. --- server/TracyView.cpp | 12 ++++++++---- server/TracyView.hpp | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/TracyView.cpp b/server/TracyView.cpp index cb477873..43e42165 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -385,15 +385,19 @@ void View::AddCustomString( uint64_t ptr, std::string&& str ) { auto pit = m_pendingCustomStrings.find( ptr ); assert( pit != m_pendingCustomStrings.end() ); - auto sit = m_customStrings.find( str ); + auto sit = m_customStrings.find( str.c_str() ); if( sit == m_customStrings.end() ) { - pit->second->text = str.c_str(); - m_customStrings.emplace( std::move( str ) ); + const auto sz = str.size(); + auto ptr = new char[sz+1]; + memcpy( ptr, str.c_str(), sz ); + ptr[sz] = '\0'; + pit->second->text = ptr; + m_customStrings.emplace( ptr ); } else { - pit->second->text = sit->c_str(); + pit->second->text = *sit; } m_pendingCustomStrings.erase( pit ); } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 92ec1cd8..5cb7ffda 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -12,6 +12,7 @@ #include "../common/tracy_lz4.hpp" #include "../common/TracySocket.hpp" #include "../common/TracyQueue.hpp" +#include "TracyCharUtil.hpp" #include "TracyEvent.hpp" #include "TracySlab.hpp" #include "TracyVector.hpp" @@ -96,7 +97,7 @@ private: Vector m_threads; std::unordered_map m_strings; std::unordered_map m_threadNames; - std::unordered_set m_customStrings; + std::unordered_set m_customStrings; std::unordered_map m_sourceLocation; uint64_t m_zonesCnt;