Source-Changes-HG archive

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

[src/trunk]: src/lib/lua/sqlite Guard against double freeing of objects (expl...



details:   https://anonhg.NetBSD.org/src/rev/66225973b364
branches:  trunk
changeset: 823813:66225973b364
user:      mbalmer <mbalmer%NetBSD.org@localhost>
date:      Wed May 10 07:36:01 2017 +0000

description:
Guard against double freeing of objects (explicit by the Lua program, then
later by the garbage collector).
This fixes PR bin/52218.

diffstat:

 lib/lua/sqlite/sqlite.c |  15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diffs (38 lines):

diff -r 0301f38a27bf -r 66225973b364 lib/lua/sqlite/sqlite.c
--- a/lib/lua/sqlite/sqlite.c   Wed May 10 06:22:15 2017 +0000
+++ b/lib/lua/sqlite/sqlite.c   Wed May 10 07:36:01 2017 +0000
@@ -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@localhost>
+ * Copyright (c) 2011, 2013, 2016, 2017 Marc Balmer <marc%msys.ch@localhost>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -120,7 +120,11 @@
        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 @@
        sqlite3_stmt **stmt;
 
        stmt = luaL_checkudata(L, 1, SQLITE_STMT_METATABLE);
-       sqlite3_finalize(*stmt);
+       if (*stmt) {
+               sqlite3_finalize(*stmt);
+               *stmt = NULL;
+       }
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index