arcapos / luapgsql

Lua binding for PostgreSQL
108 stars 24 forks source link

Potential leaks due to delayed argument checking #28

Closed daurnimator closed 8 years ago

daurnimator commented 8 years ago

e.g. in conn_sendQueryParams

If the first argument is not a pgsql connection, then it will throw at line 821. However at this point paramTypes, paramValues, etc have already been allocated.

Fix is to move those arguments check to the start of the function.

Same issue is in other places, including conn_execParams, conn_prepare, conn_execPrepared, conn_sendPrepare, conn_sendQueryPrepared,

mbalmer commented 8 years ago

Right. I moved the check for the connection object to the top of these functions (although the memory would not leak anymore due to the use of lua_newuserdata(). Thanks!

daurnimator commented 8 years ago

This matters for more than just the connection object. You should also move up the other argument checking (like luaL_checkstring).

daurnimator commented 8 years ago

You should also move up the other argument checking (like luaL_checkstring).

This was fixed in 252104788ee25610cad77abdd87ca4538865b54e