Skip to content

Commit 5c8eda1

Browse files
committed
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.
1 parent 4fbfdde commit 5c8eda1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/backend/utils/error/elog.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,15 @@ set_backtrace(ErrorData *edata, int num_skip)
11281128

11291129
nframes = backtrace(buf, lengthof(buf));
11301130
strfrms = backtrace_symbols(buf, nframes);
1131-
if (strfrms == NULL)
1132-
return;
1133-
1134-
for (int i = num_skip; i < nframes; i++)
1135-
appendStringInfo(&errtrace, "\n%s", strfrms[i]);
1136-
free(strfrms);
1131+
if (strfrms != NULL)
1132+
{
1133+
for (int i = num_skip; i < nframes; i++)
1134+
appendStringInfo(&errtrace, "\n%s", strfrms[i]);
1135+
free(strfrms);
1136+
}
1137+
else
1138+
appendStringInfoString(&errtrace,
1139+
"insufficient memory for backtrace generation");
11371140
}
11381141
#else
11391142
appendStringInfoString(&errtrace,

0 commit comments

Comments
 (0)