]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Take a little more care in set_backtrace().
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 3 Aug 2025 17:01:17 +0000 (13:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 3 Aug 2025 17:01:17 +0000 (13:01 -0400)
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.

src/backend/utils/error/elog.c

index 47af743990fe9a5819d165f73bcead833dda67d6..afce1a8e1f003094425a08aeeb9182f2e29c64fb 100644 (file)
@@ -1128,12 +1128,15 @@ set_backtrace(ErrorData *edata, int num_skip)
 
                nframes = backtrace(buf, lengthof(buf));
                strfrms = backtrace_symbols(buf, nframes);
-               if (strfrms == NULL)
-                       return;
-
-               for (int i = num_skip; i < nframes; i++)
-                       appendStringInfo(&errtrace, "\n%s", strfrms[i]);
-               free(strfrms);
+               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,