I take a look at the problem. The issue is caused by using mixed MT/MD option in one process. My DLL is using MT option and log4cxx is using MD, so they are using different copy of CRT lib. I call the LOG4CXX_DECODE_CHAR macro within my DLL to create a LogString variable then get the fail. ( note: in debug mode on windows32).
Macro: #define LOG4CXX_DECODE_CHAR(var, src) \ log4cxx::LogString var; \ log4cxx::helpers::Transcoder::decode(src, var) I check the Transcoder::decode(const std::string& src, LogString& dst) function, dst.reserve(dst.size()+src.size()); The above statement maybe allocate new bytes in the CRT heap used by log4cxx, but the dst variable would be freed in my DLL if I use the macro. The two DLLs have two different copy of CRT libs. So cause a heap corruption error. I understand if all DLLs are build with MD option, then OK. So my question is, 1. the macro LOG4CXX_DECODE_CHAR(var, src) is only used for log4cxx DLL internally? 2. Why not to only fill the memory in decode function, but not to change the size of the passed-in CRT objects? It's a rule I often use. I mean to change the size of dst object some where outside of the decode function. 3. Is it possible to create other ways to generate a logstring based on the std::string content? Thanks, Tom 2009/11/13 Zhou Tao <zhoutao...@gmail.com> > Hi all, > > I am using log4cxx on win32 platform and build the log4cxx with MT option( > Runtime Library) within MS visual Studio 2005. The project default setting > is MD. All APR, APR-UTIL and LOG4CXX projects are set to be MT mode. > > After the build, I get a crash in the LOG4CXX_DECODE_CHAR macro. The code > is very simple, looks like the below, > > void testFun() > { > std::string src = "log4cxx-string-testing"; > LOG4CXX_DECODE_CHAR(dest, src); > } > > The crash happens when leave the function when trying to delete the > allocated memory. If the length of the src string is less than 7, it works. > > Is this a problem? > > -- > Thanks and Regards, > Tom > -- Thanks and Regards, Tom