aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-09-10 13:49:04 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-09-10 13:49:04 -0400
commitfb7ed3889fa6fc0f4aa6718ffb6574801ad12484 (patch)
tree6e86c74cb0674d2746e2b9bf6009146741ac51fa /src/backend/utils/adt/pgstatfuncs.c
parent8778da2af0f4dac23b8d1ef3436b6bb0954bc013 (diff)
downloadpostgresql-fb7ed3889fa6fc0f4aa6718ffb6574801ad12484.tar.gz
postgresql-fb7ed3889fa6fc0f4aa6718ffb6574801ad12484.zip
Fix miserable coding in pg_stat_get_activity().
Commit dd1a3bccc replaced a test on whether a subroutine returned a null pointer with a test on whether &pointer->backendStatus was null. This accidentally failed to fail, at least on common compilers, because backendStatus is the first field in the struct; but it was surely trouble waiting to happen. Commit f91feba87 then messed things up further, changing the logic to local_beentry = pgstat_fetch_stat_local_beentry(curr_backend); if (!local_beentry) continue; beentry = &local_beentry->backendStatus; if (!beentry) { where the second "if" is now dead code, so that the intended behavior of printing a row with "<backend information not available>" cannot occur. I suspect this is all moot because pgstat_fetch_stat_local_beentry will never actually return null in this function's usage, but it's still very poor coding. Repair back to 9.4 where the original problem was introduced.
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 44ccd37e998..688eea12a93 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -633,15 +633,13 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
{
/* Get specific pid slot */
local_beentry = pgstat_fetch_stat_local_beentry(*(int *) (funcctx->user_fctx));
- beentry = &local_beentry->backendStatus;
}
else
{
/* Get the next one in the list */
local_beentry = pgstat_fetch_stat_local_beentry(funcctx->call_cntr + 1); /* 1-based index */
- beentry = &local_beentry->backendStatus;
}
- if (!beentry)
+ if (!local_beentry)
{
int i;
@@ -655,6 +653,8 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
}
+ beentry = &local_beentry->backendStatus;
+
/* Values available to all callers */
values[0] = ObjectIdGetDatum(beentry->st_databaseid);
values[1] = Int32GetDatum(beentry->st_procpid);