@@ -2,6 +2,7 @@ package sqlite3
2
2
3
3
import (
4
4
"context"
5
+ "io"
5
6
"sync"
6
7
7
8
"github.com/tetratelabs/wazero/api"
@@ -85,13 +86,19 @@ func (c *Conn) CreateWindowFunction(name string, nArg int, flag FunctionFlag, fn
85
86
var funcPtr ptr_t
86
87
defer c .arena .mark ()()
87
88
namePtr := c .arena .string (name )
89
+ call := "sqlite3_create_aggregate_function_go"
88
90
if fn != nil {
91
+ agg := fn ()
92
+ if c , ok := agg .(io.Closer ); ok {
93
+ if err := c .Close (); err != nil {
94
+ return err
95
+ }
96
+ }
97
+ if _ , ok := agg .(WindowFunction ); ok {
98
+ call = "sqlite3_create_window_function_go"
99
+ }
89
100
funcPtr = util .AddHandle (c .ctx , fn )
90
101
}
91
- call := "sqlite3_create_aggregate_function_go"
92
- if _ , ok := fn ().(WindowFunction ); ok {
93
- call = "sqlite3_create_window_function_go"
94
- }
95
102
rc := res_t (c .call (call ,
96
103
stk_t (c .handle ), stk_t (namePtr ), stk_t (nArg ),
97
104
stk_t (flag ), stk_t (funcPtr )))
@@ -172,7 +179,13 @@ func finalCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t)
172
179
db := ctx .Value (connKey {}).(* Conn )
173
180
fn , handle := callbackAggregate (db , pAgg , pApp )
174
181
fn .Value (Context {db , pCtx })
175
- if err := util .DelHandle (ctx , handle ); err != nil {
182
+ var err error
183
+ if handle != 0 {
184
+ err = util .DelHandle (ctx , handle )
185
+ } else if c , ok := fn .(io.Closer ); ok {
186
+ err = c .Close ()
187
+ }
188
+ if err != nil {
176
189
Context {db , pCtx }.ResultError (err )
177
190
return // notest
178
191
}
0 commit comments