summaryrefslogtreecommitdiff
path: root/lib/lua
diff options
context:
space:
mode:
authormbalmer <mbalmer@NetBSD.org>2017-05-10 07:36:01 +0000
committermbalmer <mbalmer@NetBSD.org>2017-05-10 07:36:01 +0000
commit331a688292f7a6976eceece1d5df6a65c39947cd (patch)
treebb9c55548f16085bc6936c370e049a9d8c024ab0 /lib/lua
parentf07a2c37c83837d472e9cd33f320f8ccd65850bc (diff)
Guard against double freeing of objects (explicit by the Lua program, then
later by the garbage collector). This fixes PR bin/52218.
Diffstat (limited to 'lib/lua')
-rw-r--r--lib/lua/sqlite/sqlite.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/lua/sqlite/sqlite.c b/lib/lua/sqlite/sqlite.c
index 3ffe755c2e2..e843d2e74fa 100644
--- a/lib/lua/sqlite/sqlite.c
+++ b/lib/lua/sqlite/sqlite.c
@@ -1,7 +1,7 @@
-/* $NetBSD: sqlite.c,v 1.8 2016/02/15 15:56:33 mbalmer Exp $ */
+/* $NetBSD: sqlite.c,v 1.9 2017/05/10 07:36:01 mbalmer Exp $ */
/*
- * Copyright (c) 2011, 2013, 2016 Marc Balmer <marc@msys.ch>
+ * Copyright (c) 2011, 2013, 2016, 2017 Marc Balmer <marc@msys.ch>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -120,7 +120,11 @@ db_close(lua_State *L)
sqlite3 **db;
db = luaL_checkudata(L, 1, SQLITE_DB_METATABLE);
- lua_pushinteger(L, sqlite3_close(*db));
+ if (*db) {
+ lua_pushinteger(L, sqlite3_close(*db));
+ *db = NULL;
+ } else
+ lua_pushnil(L);
return 1;
}
@@ -342,7 +346,10 @@ stmt_finalize(lua_State *L)
sqlite3_stmt **stmt;
stmt = luaL_checkudata(L, 1, SQLITE_STMT_METATABLE);
- sqlite3_finalize(*stmt);
+ if (*stmt) {
+ sqlite3_finalize(*stmt);
+ *stmt = NULL;
+ }
return 0;
}