From f890247087f7c89a7895c46e56f27facf98661d2 Mon Sep 17 00:00:00 2001 From: tomas Date: Thu, 8 May 2003 21:43:39 +0000 Subject: [PATCH] Cuidados basicos com erros durante a criacao dos objetos. --- ls_pg.c | 10 ++-------- src/ls_odbc.c | 8 ++------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/ls_pg.c b/ls_pg.c index 450d8bc..1bb2a0b 100644 --- a/ls_pg.c +++ b/ls_pg.c @@ -2,6 +2,7 @@ ** LuaSQL, PostgreSQL driver ** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Carlos Cassino ** Tomas Guisasola, Eduardo Quintao +** $Id: ls_pg.c,v 1.12 2003/05/08 21:43:39 tomas Exp $ */ #include @@ -146,13 +147,9 @@ static int cur_close (lua_State *L) { /* Nullify structure fields. */ cur->closed = 1; PQclear(cur->pg_res); - cur->pg_res = NULL; luaL_unref (L, LUA_REGISTRYINDEX, cur->conn); - cur->conn = LUA_NOREF; luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames); - cur->colnames = LUA_NOREF; luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes); - cur->coltypes = LUA_NOREF; lua_pushnumber(L, 1); return 1; @@ -315,9 +312,7 @@ static int conn_close (lua_State *L) { /* Nullify structure fields. */ conn->closed = 1; luaL_unref (L, LUA_REGISTRYINDEX, conn->env); - conn->env = LUA_NOREF; PQfinish(conn->pg_conn); - conn->pg_conn = NULL; lua_pushnumber(L, 1); return 1; } @@ -423,10 +418,9 @@ static void notice_processor (void *arg, const char *message) { ** datasource, username, password, host and port. */ static int env_connect (lua_State *L) { - /*env_data *env =*/ getenvironment (L); /* validate environment */ const char *sourcename = luaL_checkstring(L, 2); PGconn *conn; - + getenvironment (L); /* validate environment */ if ((lua_gettop (L) == 2) && (strchr (sourcename, '=') != NULL)) conn = PQconnectdb (luaL_check_string(L, 2)); else { diff --git a/src/ls_odbc.c b/src/ls_odbc.c index ee56304..b99c6cb 100644 --- a/src/ls_odbc.c +++ b/src/ls_odbc.c @@ -2,6 +2,7 @@ ** LuaSQL, ODBC driver ** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Diego Nehab, ** Tomas Guisasola +** $Id: ls_odbc.c,v 1.10 2003/05/08 21:43:39 tomas Exp $ */ #include @@ -293,7 +294,6 @@ static int cur_fetch (lua_State *L) { ** Closes a cursor. */ static int cur_close (lua_State *L) { - conn_data *conn; cur_data *cur = (cur_data *) luaL_checkudata (L, 1, LUASQL_CURSOR_ODBC); SQLHSTMT hstmt = cur->hstmt; SQLRETURN ret; @@ -311,7 +311,6 @@ static int cur_close (lua_State *L) { luaL_unref (L, LUA_REGISTRYINDEX, cur->conn); luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames); luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes); - cur->conn = LUA_NOREF; return pass(L); } @@ -393,22 +392,19 @@ static int create_cursor (lua_State *L, conn_data *conn, */ static int conn_close (lua_State *L) { SQLRETURN ret; - env_data *env; - conn_data *conn = (conn_data *) luaL_checkudata (L, 1, LUASQL_CONNECTION_ODBC); + conn_data *conn = (conn_data *)luaL_checkudata(L,1,LUASQL_CONNECTION_ODBC); if (conn->closed) return 0; /* Nullify structure fields. */ conn->closed = 1; luaL_unref (L, LUA_REGISTRYINDEX, conn->env); - conn->env = LUA_NOREF; ret = SQLDisconnect(conn->hdbc); if (error(ret)) return fail(L, hDBC, conn->hdbc); ret = SQLFreeHandle(hDBC, conn->hdbc); if (error(ret)) return fail(L, hDBC, conn->hdbc); - conn->hdbc = NULL; return pass(L); }