aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-glue.c-pp.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2025-02-03 14:55:56 +0000
committerstephan <stephan@noemail.net>2025-02-03 14:55:56 +0000
commitd98689f4d39c4729ef95a93317eaa7892a6aaed6 (patch)
tree25693d04d8fa24a67459c6a462a5ef215e14bbfb /ext/wasm/api/sqlite3-api-glue.c-pp.js
parentcf9f841c5e64a71ee5566b653c59d610e2685ac1 (diff)
downloadsqlite-d98689f4d39c4729ef95a93317eaa7892a6aaed6.tar.gz
sqlite-d98689f4d39c4729ef95a93317eaa7892a6aaed6.zip
Add a more complete test for [76c8435a] and add some commentary about (A) the inability to automatically clean up automatically-generated WASM proxy functions for sqlite3_set_auxdata() destructors and (B) how to deal with (A) to avoid leaking WASM proxy functions.
FossilOrigin-Name: d693c2dddbd10a2e0b77893b04b11502e30b768f1b06814105f7f35172845fb9
Diffstat (limited to 'ext/wasm/api/sqlite3-api-glue.c-pp.js')
-rw-r--r--ext/wasm/api/sqlite3-api-glue.c-pp.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-api-glue.c-pp.js b/ext/wasm/api/sqlite3-api-glue.c-pp.js
index ddcf2535f..bcaff7243 100644
--- a/ext/wasm/api/sqlite3-api-glue.c-pp.js
+++ b/ext/wasm/api/sqlite3-api-glue.c-pp.js
@@ -228,6 +228,31 @@ 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.
+
+ The sqlite3.oo1.DB class's onclose handlers can be used for this
+ purpose. For example:
+
+ const pAuxDtor = wasm.installFunction('v(p)', function(ptr){
+ //free ptr
+ });
+ myDb.onclose = {
+ after: ()=>{
+ wasm.uninstallFunction(pAuxDtor);
+ }
+ };
+
+ Then pass pAuxDtor as the final argument to appropriate
+ sqlite3_set_auxdata() calls.
+ */
["sqlite3_set_auxdata", undefined, [
"sqlite3_context*", "int", "*",
new wasm.xWrap.FuncPtrAdapter({
@@ -1047,6 +1072,10 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
'sqlite3_set_authorizer',
'sqlite3_trace_v2',
'sqlite3_update_hook'
+ /*
+ We do not yet have a way to clean up automatically-converted
+ sqlite3_set_auxdata() finalizers.
+ */
]) {
const x = wasm.exports[name];
if( !x ){