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 Vladislav Krejcirik <vk...@gmail.com> on 2012/05/25 09:11:54 UTC

Log4cxx and memory read problem while program is ending

Hi All,
I got very simple program in C++ which uses log4cxx for logging. I
have successfuly build log4cxx in VS 2008 and linked log4cxx.lib and
log4cxx.dll to my project. I have problem while my program is closing.
I received error message:

Unhandled exception at 0x10171754 in Log4cxxTest.exe: 0xC0000005:
Access violation reading location 0xfeeefefe.

The memory couldn't to be read.

Is there any solution how can I clean log4cxx correctly when my
program is ending? I closed my app by CTRL+C.


The code is very simple:


#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/helpers/exception.h>

using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::helpers;


LoggerPtr logger(Logger::getLogger("Log4cxxTest"));

BOOL CtrlHandler( DWORD fdwCtrlType )
{
	switch( fdwCtrlType )
	{
		// Handle the CTRL-C signal.
	case CTRL_C_EVENT:
		// CTRL-CLOSE: confirm that the user wants to exit.
	case CTRL_CLOSE_EVENT:
		// Pass other signals to the next handler.
	case CTRL_BREAK_EVENT:
	case CTRL_LOGOFF_EVENT:
	case CTRL_SHUTDOWN_EVENT:
		{
			LOG4CXX_INFO(logger, "END.");
			return FALSE;
		}
	default:
		return FALSE;
	}
}


int _tmain(int argc, _TCHAR* argv[])
{
		int result = EXIT_SUCCESS;
	try
	{
		BasicConfigurator::configure();

		if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
		{ 	
			while( 1 ){ }
		}
		else
		{
			LOG4CXX_ERROR(logger, "Could not set control handler.");
			return EXIT_FAILURE;
		}

	}
	catch(Exception&)
	{
		result = EXIT_FAILURE;
	}

	return result;
}

Thanks for all replies!

Re: Log4cxx and memory read problem while program is ending

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Vladislav Krejcirik,
am Freitag, 25. Mai 2012 um 10:02 schrieben Sie:

> Thanks for reply! I'm not sure, but I changed code for handling CTRL+C
> and issue looks like fixed. May be it was not problem with log4cxx..

I don't know about that handler but in the former version you logged
on CTRL_SHUTDOWN_EVENT and maybe this event was fired after log4xx was
already destructed right before the application shutdown.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon.............030-2 1001-310
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hanover HRB 207 694 - Geschäftsführer: Andreas Muchow


Re: Log4cxx and memory read problem while program is ending

Posted by Mehrwash Faruqi <en...@gmail.com>.
[image: Inline image 1]

On Fri, May 25, 2012 at 1:02 PM, Vladislav Krejcirik
<vk...@gmail.com>wrote:

> Hi,
> Thanks for reply! I'm not sure, but I changed code for handling CTRL+C
> and issue looks like fixed. May be it was not problem with log4cxx..
> Code looks now like this:
>
> #include <windows.h>
> #include <stdio.h>
>
> #include <log4cxx/logger.h>
> #include <log4cxx/xml/domconfigurator.h>
> #include <log4cxx/basicconfigurator.h>
> #include <log4cxx/helpers/exception.h>
>
> using namespace log4cxx;
> using namespace log4cxx::xml;
> using namespace log4cxx::helpers;
>
>
> LoggerPtr logger(Logger::getLogger("Log4cxxTest"));
>
> static volatile bool g_exit = false;
>
> static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
> {
>  g_exit = true;
>  return TRUE;
> }
>
>
> int _tmain(int argc, _TCHAR* argv[])
> {
>                int result = EXIT_SUCCESS;
>        try
>        {
>                 // Load configuration file
>                //DOMConfigurator::configure("PIAdapterLogConfig.xml");
>                //PropertyConfigurator::configure("PIAdapterLogConfig.xml");
>                BasicConfigurator::configure();
>
>  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
>
>  while (!g_exit);
>
>        }
>        catch(Exception&)
>        {
>                result = EXIT_FAILURE;
>        }
>
>        return result;
> }
>
>
>
> On Fri, May 25, 2012 at 9:46 AM, Thorsten Schöning
> <ts...@am-soft.de> wrote:
> > Guten Tag Vladislav Krejcirik,
> > am Freitag, 25. Mai 2012 um 09:11 schrieben Sie:
> >
> >> Unhandled exception at 0x10171754 in Log4cxxTest.exe: 0xC0000005:
> >> Access violation reading location 0xfeeefefe.
> >
> > There are known problems in the shutdown of log4cxx, the following may
> > help. I had to uncomment the call to apr_terminate in some classes.
> >
> >
> http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/200901.mbox/%3C4975157F.8070001@purplescarab.com%3E
> >
> > Mit freundlichen Grüßen,
> >
> > Thorsten Schöning
> >
> > --
> > Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
> > AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
> >
> > Telefon.............030-2 1001-310
> > Fax...............05151-  9468- 88
> > Mobil..............0178-8 9468- 04
> >
> > AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> > AG Hanover HRB 207 694 - Geschäftsführer: Andreas Muchow
> >
>
>
>
> --
> /**************************************/
> Best regards / S pozdravem
> Vladislav Krejčiřík
>
> http://www.vkrejcirik.info
>



-- 
Mehrwash Faruqi

Re: Log4cxx and memory read problem while program is ending

Posted by Vladislav Krejcirik <vk...@gmail.com>.
Hi,
Thanks for reply! I'm not sure, but I changed code for handling CTRL+C
and issue looks like fixed. May be it was not problem with log4cxx..
Code looks now like this:

#include <windows.h>
#include <stdio.h>

#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/helpers/exception.h>

using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::helpers;


LoggerPtr logger(Logger::getLogger("Log4cxxTest"));

static volatile bool g_exit = false;

static BOOL WINAPI console_ctrl_handler(DWORD dwCtrlType)
{
  g_exit = true;
  return TRUE;
}


int _tmain(int argc, _TCHAR* argv[])
{
		int result = EXIT_SUCCESS;
	try
	{
		// Load configuration file
		//DOMConfigurator::configure("PIAdapterLogConfig.xml");
		//PropertyConfigurator::configure("PIAdapterLogConfig.xml");
		BasicConfigurator::configure();

  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);

  while (!g_exit);

	}
	catch(Exception&)
	{
		result = EXIT_FAILURE;
	}

	return result;
}



On Fri, May 25, 2012 at 9:46 AM, Thorsten Schöning
<ts...@am-soft.de> wrote:
> Guten Tag Vladislav Krejcirik,
> am Freitag, 25. Mai 2012 um 09:11 schrieben Sie:
>
>> Unhandled exception at 0x10171754 in Log4cxxTest.exe: 0xC0000005:
>> Access violation reading location 0xfeeefefe.
>
> There are known problems in the shutdown of log4cxx, the following may
> help. I had to uncomment the call to apr_terminate in some classes.
>
> http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/200901.mbox/%3C4975157F.8070001@purplescarab.com%3E
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
>
> Telefon.............030-2 1001-310
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hanover HRB 207 694 - Geschäftsführer: Andreas Muchow
>



-- 
/**************************************/
Best regards / S pozdravem
Vladislav Krejčiřík

http://www.vkrejcirik.info

Re: Log4cxx and memory read problem while program is ending

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Vladislav Krejcirik,
am Freitag, 25. Mai 2012 um 09:11 schrieben Sie:

> Unhandled exception at 0x10171754 in Log4cxxTest.exe: 0xC0000005:
> Access violation reading location 0xfeeefefe.

There are known problems in the shutdown of log4cxx, the following may
help. I had to uncomment the call to apr_terminate in some classes.

http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/200901.mbox/%3C4975157F.8070001@purplescarab.com%3E

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon.............030-2 1001-310
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hanover HRB 207 694 - Geschäftsführer: Andreas Muchow