@@ -649,6 +649,10 @@ receive_array(SHMRequest request, Size item_size, Size *count)
649649pgws_collector_hdr -> request = request ;
650650LockRelease (& collectorTag ,ExclusiveLock , false);
651651
652+ /*
653+ * Check that the collector was started to avoid NULL
654+ * pointer dereference.
655+ */
652656if (!pgws_collector_hdr -> latch )
653657ereport (ERROR , (errcode (ERRCODE_INTERNAL_ERROR ),
654658errmsg ("pg_wait_sampling collector wasn't started" )));
@@ -819,6 +823,14 @@ pg_wait_sampling_reset_profile(PG_FUNCTION_ARGS)
819823pgws_collector_hdr -> request = PROFILE_RESET ;
820824LockRelease (& collectorTag ,ExclusiveLock , false);
821825
826+ /*
827+ * Check that the collector was started to avoid NULL
828+ * pointer dereference.
829+ */
830+ if (!pgws_collector_hdr -> latch )
831+ ereport (ERROR , (errcode (ERRCODE_INTERNAL_ERROR ),
832+ errmsg ("pg_wait_sampling collector wasn't started" )));
833+
822834SetLatch (pgws_collector_hdr -> latch );
823835
824836LockRelease (& queueTag ,ExclusiveLock , false);