mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Take a little more care in set_backtrace().
Coverity complained that the "errtrace" string is leaked if we return early because backtrace_symbols fails. Another criticism that could be leveled at this is that not providing any hint of what happened is user-unfriendly. Fix that. The odds of a leak here are small, and typically it wouldn't matter anyway since the leak will be in ErrorContext which will soon get reset. So I'm not feeling a need to back-patch.
This commit is contained in:
@@ -1128,13 +1128,16 @@ set_backtrace(ErrorData *edata, int num_skip)
|
||||
|
||||
nframes = backtrace(buf, lengthof(buf));
|
||||
strfrms = backtrace_symbols(buf, nframes);
|
||||
if (strfrms == NULL)
|
||||
return;
|
||||
|
||||
if (strfrms != NULL)
|
||||
{
|
||||
for (int i = num_skip; i < nframes; i++)
|
||||
appendStringInfo(&errtrace, "\n%s", strfrms[i]);
|
||||
free(strfrms);
|
||||
}
|
||||
else
|
||||
appendStringInfoString(&errtrace,
|
||||
"insufficient memory for backtrace generation");
|
||||
}
|
||||
#else
|
||||
appendStringInfoString(&errtrace,
|
||||
"backtrace generation is not supported by this installation");
|
||||
|
Reference in New Issue
Block a user