Problem:
========

On windows when we run edb-postgres.exe without any command line args, its
getting crash or its showing error into Application logs of Event Viewer.

Analysis:
==========

For any stderr we call the write_stderr() and write_stderr() calls the
write_console() for stderr. Now here write_console() using the palloc()
internally, which require the CurrentMemoryContext.

At the startup CurrentMemoryContext will be NULL, so palloc again calling
write_stderr(). So recursion has been started and its ending up with
exception.

Call stack for palloc() is:

main() -> check_root() -> write_stderr() -> write_console() ->
pgwin32_toUTF16() -> palloc()

Fix:
=====

Earlier  we used to call vfprintf() for windows stderr, which is now
replaced with write_console().
So to avoid the exception now, I added condition for CurrentMemoryContext
into write_stderr().

PFA patch to fix the same.

Regards,
Rushabh Lathia
EnterpriseDB <http://www.enterprisedb.com/>, The Enterprise
PostgreSQL<http://www.enterprisedb.com/>
 company.
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /repositories/postgreshome/cvs/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.226
diff -c -p -r1.226 elog.c
*** src/backend/utils/error/elog.c	19 Aug 2010 22:55:01 -0000	1.226
--- src/backend/utils/error/elog.c	1 Apr 2011 14:08:38 -0000
*************** write_stderr(const char *fmt,...)
*** 2759,2766 ****
  	}
  	else
  	{
! 		/* Not running as service, write to stderr */
! 		write_console(errbuf, strlen(errbuf));
  		fflush(stderr);
  	}
  #endif
--- 2759,2773 ----
  	}
  	else
  	{
! 		/* 
! 		 * To use the write_console we need memoryContext as its using palloc
! 		 * internally. When we don't have CurrentMemoryContext directly throw
! 		 * error at stderr.
! 		 */
! 		if (CurrentMemoryContext)
! 			write_console(errbuf, strlen(errbuf));
! 		else
! 			vfprintf(stderr, fmt, ap);
  		fflush(stderr);
  	}
  #endif
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to