lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
539 stars 191 forks source link

env_connect postgres libpq memory leak #45

Closed seanpringle closed 8 years ago

seanpringle commented 8 years ago

Before I go down this rabbit hole, a quick question in case I'm missing something obvious:

Ubuntu 14.04 LTS lua-sql-postgres:amd64 2.3.0-3

Am seeing a memory leak when luasql fails to connect to Postgres. Memory footprint increases steadily for a long-running script with persistent connections that periodically attempts to reconnect to a database that is temporarily offline.

Is it intentional that ls_postgres.c env_connect() does not call PQfinish() when PQstatus() returns CONNECTION_BAD? At first glance it looks like a failed PGconn struct will never be seen by conn_gc().

According to libpq docs [1] PQfinish() should be called even when a PQstatus() returns CONNECTION_BAD in order to release any memory allocated by libpq during the connection attempt.

[1] http://www.postgresql.org/docs/9.5/static/libpq-connect.html#LIBPQ-PQFINISH

tomasguisasola commented 8 years ago

Thanks for pointing out the problem. I think it is corrected now. Could you, please, check the new version 2.3.2?

seanpringle commented 8 years ago

Thanks. 2.3.2 fixes the memory leak, but also causes #46.

tomasguisasola commented 8 years ago

Sure, my bad. I hope the problem is now corrected.

Thanks, Tomás

On 2016-05-15 21:18, seanpringle wrote:

Thanks. 2.3.2 fixes the memory leak, but also causes #45 [1].

You are receiving this because you commented. Reply to this email directly or view it on GitHub [2]

*

Links:

[1] https://github.com/keplerproject/luasql/issues/45 [2] https://github.com/keplerproject/luasql/issues/45#issuecomment-219323792