diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/error/elog.c | 21 | ||||
-rw-r--r-- | src/backend/utils/mmgr/mcxt.c | 6 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 3de162b9d53..8705586d565 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -311,6 +311,18 @@ errstart(int elevel, const char *filename, int lineno, return false; /* + * We need to do some actual work. Make sure that memory context + * initialization has finished, else we can't do anything useful. + */ + if (ErrorContext == NULL) + { + /* Ooops, hard crash time; very little we can do safely here */ + write_stderr("error occurred at %s:%d before error message processing is available\n", + filename ? filename : "(unknown file)", lineno); + exit(2); + } + + /* * Okay, crank up a stack entry to store the info in. */ @@ -1238,6 +1250,15 @@ elog_start(const char *filename, int lineno, const char *funcname) { ErrorData *edata; + /* Make sure that memory context initialization has finished */ + if (ErrorContext == NULL) + { + /* Ooops, hard crash time; very little we can do safely here */ + write_stderr("error occurred at %s:%d before error message processing is available\n", + filename ? filename : "(unknown file)", lineno); + exit(2); + } + if (++errordata_stack_depth >= ERRORDATA_STACK_SIZE) { /* diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index b60ca90d0a3..7b089f77df8 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -72,7 +72,8 @@ static void MemoryContextStatsInternal(MemoryContext context, int level); * In normal multi-backend operation, this is called once during * postmaster startup, and not at all by individual backend startup * (since the backends inherit an already-initialized context subsystem - * by virtue of being forked off the postmaster). + * by virtue of being forked off the postmaster). But in an EXEC_BACKEND + * build, each process must do this for itself. * * In a standalone backend this must be called during backend startup. */ @@ -106,6 +107,9 @@ MemoryContextInit(void) * where retained memory in a context is *essential* --- we want to be * sure ErrorContext still has some memory even if we've run out * elsewhere! + * + * This should be the last step in this function, as elog.c assumes memory + * management works once ErrorContext is non-null. */ ErrorContext = AllocSetContextCreate(TopMemoryContext, "ErrorContext", |