Skip to content

memory leak in pg_stat_monitor #628

@surajkharage19

Description

@surajkharage19

Description

Hi,

While working on another issue, identified a memory leak in pg_stat_monitor specifically occurring when commands are invoked via the SPI infrastructure within a Background Worker.

The root cause appears to be in the cleanup callback registration. https://github.com/percona/pg_stat_monitor/blob/main/pg_stat_monitor.c#L398
The current logic only registers the cleanup callback if MessageContext is valid. However, when executing via SPI in a Background Worker, MessageContext is typically unavailable.
Consequently, the cleanup function is never triggered, leading to a memory leak.

Attaching the sample contrib which can be used to identify the issue, just need to install the module and add entry in shared_preload_library.

Can you please check this?

spi_sample.patch

Expected Results

N/A

Actual Results

N/A

Version

Postgres 18, pg_stat_monitor 2.3

Steps to reproduce

No response

Relevant logs

Code of Conduct

  • I agree to follow Percona Community Code of Conduct

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions