I like to store a hash of the last message avoiding duplicate messages send by my MQTT project. I like to use a dictionary created via lib. Actually I store the char array for testing and facing the behavior that the char array stored gets corrupted from time to time.
My debugging output looks like this with random symbols but it should show the same string twice:
You didn't post a complete code, so I can only supply an incomplete answer. I'm guessing it's because you don't actually store the data in your std::map, you just store a pointer to it. I'd say the memory being pointed to is later deallocated, reused, or otherwise becomes invalid.
I won't be clicking on a random link of unknown provenance. Post the code here, in-line, with code tags.
Also tell us exactly which Arduino board you're compiling for, which version of the Arduino Core for that board, and exactly which versions of libraries you're using.
EDIT:
BTW, you don't need to use find() to see if topic is already in the map. The emplace() function will do that for you and only add to the map if the topic doesn't already exist.
I ask ChatGPT and it give me the technical correct answer. With str::map only types can be used that are comparable via ==,.. . This is not the case for a char array. I use now std::map<const String, const String> and it seems working fine.