postgres.git / summary / log / commit / refs
commit 681690f4e374d88877ea2f4de1baa04f780abd8e
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: Sat Jul 21 22:12:38 2007 +0000
First released in: 8.3.0, 7.3.20, 7.4.18, 8.0.14, 8.1.10, 8.2.5
Fix elog.c to avoid infinite recursion (leading to backend crash) when
log_min_error_statement is active and there is some problem in logging the
current query string; for example, that it's too long to include in the log
message without running out of memory. This problem has existed since the
log_min_error_statement feature was introduced. No doubt the reason it
wasn't detected long ago is that 8.2 is the first release that defaults
log_min_error_statement to less than PANIC level.
Per report from Bill Moran.
src/backend/utils/error/elog.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index b2b431a984e..513288cd08b 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.1 2005/10/14 16:41:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.104.2.2 2007/07/21 22:12:38 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -429,13 +429,18 @@ elog(int lev, const char *fmt,...)
free(msg_buf);
/*
- * If the user wants this elog() generating query logged, do so. We
- * only want to log if the query has been written to
- * debug_query_string. Also, avoid infinite loops.
+ * If the user wants this elog() generating query logged, do so.
+ * To avoid possible infinite recursion, temporarily clear
+ * debug_query_string while recursing.
*/
+ if (lev >= log_min_error_statement && debug_query_string)
+ {
+ char *q_str = debug_query_string;
- if (lev != LOG && lev >= log_min_error_statement && debug_query_string)
- elog(LOG, "statement: %s", debug_query_string);
+ debug_query_string = NULL;
+ elog(LOG, "statement: %s", q_str);
+ debug_query_string = q_str;
+ }
/*
* Perform error recovery action as specified by lev.
[parent: c556447c70c9]