1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Rework [76c8435a] to eliminate automatic JS-to-WASM function conversions of sqlite3_set_auxdata() destructors because it can leads to leaks on every call of a UDF. This feature never worked before [76c8435a] but fixing it was ill-conceived because of the memory leakage it introduces. WASM function pointers can still be used as destructors in this context.

FossilOrigin-Name: 3fb993af0caf041da934cea29c039b27c468be0b75bce1537a6425767cf9bf8d
This commit is contained in:
stephan
2025-02-03 17:34:12 +00:00
parent d98689f4d3
commit 3cd34ab981
4 changed files with 35 additions and 24 deletions

View File

@@ -229,14 +229,15 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
'*'
]],
/**
2025-02-03: We do not have a way to automatically clean up
destructors which are automatically converted from JS functions
via the final argument to sqlite3_set_auxdata(). Because of
that, it is strongly recommended that clients use
wasm.installFunction() to create such callbacks, then pass that
pointer to sqlite3_set_auxdata(). Relying on automated
conversions here will lead to leaks of JS/WASM proxy functions
because sqlite3_set_auxdata() is frequently called in UDFs.
We do not have a way to automatically clean up destructors
which are automatically converted from JS functions via the
final argument to sqlite3_set_auxdata(). Because of that,
automatic function conversion is not supported for this
function. Clients should use wasm.installFunction() to create
such callbacks, then pass that pointer to
sqlite3_set_auxdata(). Relying on automated conversions here
would lead to leaks of JS/WASM proxy functions because
sqlite3_set_auxdata() is frequently called in UDFs.
The sqlite3.oo1.DB class's onclose handlers can be used for this
purpose. For example:
@@ -252,14 +253,24 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
Then pass pAuxDtor as the final argument to appropriate
sqlite3_set_auxdata() calls.
Note that versions prior to 3.49.0 ostensibly had automatic
function conversion here but a typo prevented it from
working. Rather than fix it, it was removed because testing the
fix brought the huge potential for memory leaks to the
forefront.
*/
["sqlite3_set_auxdata", undefined, [
"sqlite3_context*", "int", "*",
new wasm.xWrap.FuncPtrAdapter({
name: 'xDestroyAuxData',
signature: 'v(p)',
contextKey: (argv, argIndex)=>argv[0/* sqlite3_context* */]
})
true
? "*"
: new wasm.xWrap.FuncPtrAdapter({
/* If we can find a way to automate their cleanup, JS functions can
be auto-converted with this. */
name: 'xDestroyAuxData',
signature: 'v(p)',
contextKey: (argv, argIndex)=>argv[0/* sqlite3_context* */]
})
]],
["sqlite3_shutdown", undefined],
["sqlite3_sourceid", "string"],