You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Noam Rathaus <no...@beyondsecurity.com> on 2010/10/17 15:53:18 UTC

log4cxx crash after call to setFile

Hi,

I am trying to use the following code in Visual Studio 2010, under the
previous version of Visual Studio it worked without a hitch, now it
crashes:
LogString strLayout(LOG4CXX_STR("[%d{yyyy-MM-dd HH:mm:ss}, %p]%m%n"));
log4cxx::PatternLayoutPtr FileLayout = new log4cxx::PatternLayout(strLayout);

log4cxx::RollingFileAppenderPtr pFileAppMain(new
log4cxx::RollingFileAppender());

pFileAppMain->setLayout(FileLayout);
pFileAppMain->setFile(log4cxx::helpers::Transcoder::decode(m_Filename.c_str()));


m_Filename is set as:
static std::string CLogger::m_Filename = "";

And assigned a value of "c:\LOGLOCATION\" just before the above code is called.

The code variable is set as static as the CLogger code is called by
several functions, so I want the log object to be shared.

This is the crash:
       GUI.exe!_CrtIsValidHeapPointer(const void * pUserData)  Line
2036       C++
       GUI.exe!_free_dbg_nolock(void * pUserData, int nBlockUse)  Line 1322
+ 0x9 bytes     C++
       GUI.exe!_free_dbg(void * pUserData, int nBlockUse)  Line 1265 +
0xd bytes       C++
       GUI.exe!operator delete(void * p)  Line 347 + 0xb bytes C++
       GUI.exe!std::allocator<wchar_t>::deallocate(wchar_t * _Ptr, unsigned
int __formal)  Line 182 + 0x9 bytes     C++
       GUI.exe!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>
>::_Tidy(bool _Built, unsigned int _Newsize)  Line 1998 C++
       GUI.exe!std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>
>::~basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>
>()  Line 755   C++
       GUI.exe!CLogger::initLog4cxx(std::basic_string<char,std::char_traits<char>,std::allocator<char>
> logThreads, std::basic_string<char,std::char_traits<char>,std::allocator<char>
> logExceptions)  Line 95       C++


I believe the problem is because std::string is going out of context
and the log4cxx hasn't made a copy of it.

Thanks,
Noam Rathaus