It looks like SymbolLookup
API you’re hooking into is assuming that the symbols are stored in a quasi-permanent structure and not generated on the fly. If your symbols are really transient, you need to make them permanent in some way, either C style through something like
return strdup(myString.c_str());
or in a more idiomatic C++ style with:
static std::vector<std::string> sStringPool;
sStringPool.push_back(myString);
return sStringPool.back().c_str();
Naturally, this is going to lead to unbounded memory growth, but if you have no other information about string lifetimes, there are few alternatives. If you want to get clever, you can at least unique the strings:
static std::set<std::string> sStringPool;
return sStringPool.insert(sStringPool.end(), myString)->c_str();