• 15
• 15
• 11
• 9
• 10

DLL Memory Question

This topic is 4966 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm baffled. The best way to explain what's going on is by using some code, so, here goes!
// this is inside a dll file, engine.dll
void Log::GetBuffer(std::string& str) {
// m_Buffer is an std::stringstream member
// of the class Log
str = m_Buffer.str();
}

// ------------------

// this is inside of the calling application
std::string logdata;


Now, inasmuch as I understand it, those two functions should work without error; and, in a way, they do. If I run the application without debugging, everything appears to work fine. However! If I run the app with debugging, when the application closes it throws an unhandled exception (which I know has something to do with how logdata is assigned) of the following: Invalid Address specified to RtlFreeHeap. This looks like some kind of Run Time Library issue, but why? "str" is simply getting a copy of some data that lies inside the dll? I fear this is a hint of a really bad memory leak, but according to the code (and what I understand of C++) it shouldn't be. I tried just returning the entire std::string, but you can't easily pass structures across a dll like that--at least, not STL structures (this is a known issue). I also tried the nasty practice of having a function within the DLL declare some memory on the heap and having the app give the dll a pointer with which the dll would allocate--leaving the cleanup to the app. That was just silly, and didn't work anyways. Can anyone offer some insight as to what's going on? Thanks...