Re: [PATCH] Fix Potential Memory Leak in pg_amcheck Code
От | Daniel Gustafsson |
---|---|
Тема | Re: [PATCH] Fix Potential Memory Leak in pg_amcheck Code |
Дата | |
Msg-id | 3DA7CECD-5A05-416D-8527-ABD794AEFE8B@yesql.se обсуждение исходный текст |
Ответы |
Re: [PATCH] Fix Potential Memory Leak in pg_amcheck Code
|
Список | pgsql-hackers |
> On 7 Feb 2025, at 08:04, Saladin <312199339@qq.com> wrote: > > Dear pgsql-hackers, > > While reviewing the code of pg_amcheck, I discovered a potential issue that could lead to a memory leak. Specifically,there is a missing PQclear(result) call before the database connection is disconnected, which could leave thequery result unfreed. > > To resolve this, I have created a patch that ensures PQclear(result) is called prior to the disconnectDatabase(conn) function.This small change ensures proper memory management by cleaning up the query result before closing the connection. We typically don't worry too much about small leaks in client applications, as they will be cleaned up when the program exits. That being said, there is value in doing the right thing and setting good examples in our own code as many do read it and reference it. This fix ties in nicely with f3e4aeb744da which fixed another libpq usage pattern (albeit a more interesting one). There are two more cases of not calling PQclear() before disconnecting, both of which are immediately followed by exit(1) calls. We call PQclear on such a case elsewhere in the file so it's not entirely consistent, but it's not all that important as the memory will be reclaimed at exit. > I would appreciate any feedback or suggestions on this fix. If it looks good, I would be happy to proceed with any necessarysteps to contribute it to the project. Since you've submitted a patch you have already performed the necessary steps, thanks for your contribution! -- Daniel Gustafsson
В списке pgsql-hackers по дате отправления: