mwild1 / luadbi

Multi-backend SQL database library for Lua
MIT License
38 stars 14 forks source link

Segfault in SQLite3 driver #35

Closed Zash closed 8 years ago

Zash commented 8 years ago

From the well don't do that then department:

local DBI = require "DBI"
local db = DBI.Connect("SQLite3", ":memory:");
local stmt = db:prepare("SELECT 1");
db:close()
stmt:execute()

This code segfaults, since the database conn is (obviously) no longer valid.

(gdb) bt full
#0  sqlite3_get_autocommit (db=0x0) at sqlite3.c:127785
No locals.
#1  0x00007ffff6c98368 in begin (conn=0x63af58) at dbd/sqlite3/connection.c:19
No locals.
#2  try_begin_transaction (conn=0x63af58) at dbd/sqlite3/connection.c:37
No locals.
#3  0x00007ffff6c98d51 in statement_execute (L=0x62c010)
    at dbd/sqlite3/statement.c:193
        n = 1
        statement = 0x64ce38
        p = <optimized out>
        errflag = 0
        errstr = <optimized out>
        expected_params = <optimized out>
        num_bind_params = 0
sparked435 commented 8 years ago

Agreed, this is in the "well don't do that then" department :)

I think this should raise a catchable error. Committed a unit test for it; fix forthcoming as soon as I find the time.

Zash commented 8 years ago

A lua_error() would be much preferable to SIGSEGV :)

sparked435 commented 8 years ago

Fixed in all open-source drivers. DB2 and Oracle aren't being tested yet, so I'm going close this issue as fixed.