[PATCH] Fix Potential Memory Leak in pg_amcheck Code

Saladin <312199339@qq.com>

From: Saladin <312199339@qq.com>
To: pgsql-hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-02-07T07:04:45Z
Lists: pgsql-hackers

Attachments

Dear pgsql-hackers,




While reviewing the code of&nbsp;pg_amcheck, I discovered a potential issue that could lead to a memory leak. Specifically, there is a missing&nbsp;PQclear(result)&nbsp;call before the database connection is disconnected, which could leave the query result unfreed.




To resolve this, I have created a patch that ensures&nbsp;PQclear(result)&nbsp;is called prior to the&nbsp;disconnectDatabase(conn)&nbsp;function. This small change ensures proper memory management by cleaning up the query result before closing the connection.




Please find the patch attached for your review.




I would appreciate any feedback or suggestions on this fix. If it looks good, I would be happy to proceed with any necessary steps to contribute it to the project.

Thank you for your time and consideration.




--

Best regards,
JiaoShuntian,
Highgo Software.

Commits

  1. pg_amcheck: PQclear query results