pgsql: Improve checks and error messages of pgstat_register_kind()

Started by Michael Paquier5 months ago1 messagescommitters
Jump to latest
#1Michael Paquier
michael@paquier.xyz

Improve checks and error messages of pgstat_register_kind()

pgstat_register_kind() did not validate that required callbacks are
set, which could lead to NULL pointer dereferences when trying to
register a stats kind. This adds a couple of checks:
- Fox fixed-sized kinds, init_shmem_cb, reset_all_cb, and snapshot_cb
are required.
- For variable-sized kinds, flush_pending_cb is called when there is
pending data, pending_size being required.

These issues should be easy to notice for someone developing an
extension that relies on the custom pgstats APIs. No backpatch is done
as it is mainly a life improvement.

Author: Sami Imseih <samimseih@gmail.com>
Discussion: /messages/by-id/CAA5RZ0uNoe=xT7QsU1K0mMRg-QAwPtupPWZ2J3weM2PjVL2tiA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a924407ce0264ccb8fcea0de9c6f0573d24b57a7

Modified Files
--------------
src/backend/utils/activity/pgstat.c | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)