Skip to content

Commit 218fc7e

Browse files
committed
Attempt to fix segfaults in finalizers.
Remove all finalizers from SQLiteStmt and instead explicitly close any instances of SQLiteStmt.
1 parent 73f2479 commit 218fc7e

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/SQLite.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ end
6060

6161
function Base.close{T}(db::SQLiteDB{T})
6262
db.handle == C_NULL && return
63-
# Close all prepared statements with db
64-
stmt = C_NULL
65-
while true
66-
stmt = sqlite3_next_stmt(db.handle,stmt)
67-
stmt == C_NULL && break
68-
@CHECK db sqlite3_finalize(stmt)
69-
end
7063
@CHECK db sqlite3_close(db.handle)
7164
db.handle = C_NULL
7265
return
@@ -87,7 +80,6 @@ function SQLiteStmt{T}(db::SQLiteDB{T},sql::String)
8780
handle = [C_NULL]
8881
sqliteprepare(db,sql,handle,[C_NULL])
8982
stmt = SQLiteStmt(db,handle[1],convert(T,sql))
90-
finalizer(stmt, close)
9183
return stmt
9284
end
9385

@@ -136,6 +128,7 @@ end
136128
function execute(db::SQLiteDB,sql::String)
137129
stmt = SQLiteStmt(db,sql)
138130
execute(stmt)
131+
close(stmt)
139132
return changes(db)
140133
end
141134

@@ -146,6 +139,7 @@ function query(db::SQLiteDB,sql::String)
146139
status = execute(stmt)
147140
ncols = sqlite3_column_count(stmt.handle)
148141
if status == SQLITE_DONE || ncols == 0
142+
close(stmt)
149143
return changes(db)
150144
end
151145
colnames = Array(String,ncols)
@@ -177,6 +171,7 @@ function query(db::SQLiteDB,sql::String)
177171
end
178172
status = sqlite3_step(stmt.handle)
179173
end
174+
close(stmt)
180175
if status == SQLITE_DONE
181176
return ResultSet(colnames, results)
182177
else
@@ -279,6 +274,7 @@ function create(db::SQLiteDB,name::String,table,
279274
end
280275
execute(stmt)
281276
end
277+
close(stmt)
282278
end
283279
execute(db,"analyze $name")
284280
return changes(db)
@@ -307,6 +303,7 @@ function append(db::SQLiteDB,name::String,table)
307303
end
308304
execute(stmt)
309305
end
306+
close(stmt)
310307
end
311308
execute(db,"analyze $name")
312309
return return changes(db)

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ if VERSION > v"0.4.0-"
5959
@test size(r) == (10,5)
6060
@test typeof(r[1,5]) == Date
6161
@test all(r[:,5] .== Date(2014,1,1))
62+
close(stmt)
6263
end
6364
@test query(db,"drop table temp") == EMPTY_RESULTSET
6465

@@ -106,4 +107,4 @@ end
106107
@test size(tables(db)) == (11,1)
107108

108109
close(db)
109-
close(db) # repeatedly trying to close db
110+
close(db) # repeatedly trying to close db

0 commit comments

Comments
 (0)