lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hi

ls_postgres.c fails to free query results when no tupels are returned.
This is unchanged in LuaSQL 2.0.1 and the current 2.0.2
and probably also affects earlier versions.

patch attached
--- ls_postgres.c~	2006-09-14 17:43:09.000000000 +0200
+++ ls_postgres.c	2006-09-18 11:10:30.000000000 +0200
@@ -341,14 +341,14 @@
 	if (res && PQresultStatus(res)==PGRES_COMMAND_OK) {
 		/* no tuples returned */
 		lua_pushnumber(L, atof(PQcmdTuples(res)));
+		PQclear(res);
 		return 1;
 	}
-	else if (res && PQresultStatus(res)==PGRES_TUPLES_OK)
-		/* tuples returned */
+	if (res && PQresultStatus(res)==PGRES_TUPLES_OK) /* tuples returned */
 		return create_cursor (L, 1, res);
-	else
-		/* error */
-		return luasql_faildirect(L, PQerrorMessage(conn->pg_conn));
+	/* error */
+	PQclear(res);
+	return luasql_faildirect(L, PQerrorMessage(conn->pg_conn));
 }
 
 
@@ -432,7 +432,7 @@
 	PGconn *conn;
 	getenvironment (L);	/* validate environment */
 	if ((lua_gettop (L) == 2) && (strchr (sourcename, '=') != NULL))
-		conn = PQconnectdb (luaL_check_string(L, 2));
+		conn = PQconnectdb (sourcename);
 	else {
 		const char *username = luaL_optstring(L, 3, NULL);
 		const char *password = luaL_optstring(L, 4, NULL);