Skip to content

Commit 1a250c8

Browse files
Shapovalov KirillShapovalov Kirill
authored andcommitted
fix function pointer leak
1 parent be04bc1 commit 1a250c8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/api.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class Database
244244
@db = getValue(apiTemp, 'i32')
245245
RegisterExtensionFunctions(@db)
246246
@statements = {} # A list of all prepared statements of the database
247+
@functions = [] # A list of all user function (created by create_function call) of the database
247248

248249
### Execute an SQL query, ignoring the rows it returns.
249250
@@ -395,6 +396,7 @@ class Database
395396
###
396397
'export': ->
397398
stmt['free']() for _,stmt of @statements
399+
removeFunction(func) for func in @functions
398400
@handleError sqlite3_close_v2 @db
399401
binaryDb = FS.readFile @filename, encoding:'binary'
400402
@handleError sqlite3_open @filename, apiTemp
@@ -414,6 +416,7 @@ class Database
414416
###
415417
'close': ->
416418
stmt['free']() for _,stmt of @statements
419+
removeFunction(func) for func in @functions
417420
@handleError sqlite3_close_v2 @db
418421
FS.unlink '/' + @filename
419422
@db = null
@@ -481,5 +484,6 @@ class Database
481484

482485
# Generate a pointer to the wrapped, user defined function, and register with SQLite.
483486
func_ptr = addFunction(wrapped_func)
487+
@functions.push(func_ptr);
484488
@handleError sqlite3_create_function_v2 @db, name, func.length, SQLite.UTF8, 0, func_ptr, 0, 0, 0
485489
return @

0 commit comments

Comments
 (0)