Skip to content

Commit 7b30026

Browse files
add finalizer for ExecContext
1 parent b897f14 commit 7b30026

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

chdb/driver/driver.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"database/sql"
77
"database/sql/driver"
88
"fmt"
9+
"runtime"
910
"strconv"
1011
"strings"
1112

@@ -352,10 +353,16 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
352353
if err != nil {
353354
return nil, err
354355
}
355-
return &execResult{
356+
res := &execResult{
356357
err: nil,
357358
localRes: result,
358-
}, nil
359+
}
360+
runtime.SetFinalizer(res, func(r *execResult) {
361+
if r.localRes != nil {
362+
r.localRes.Free()
363+
}
364+
})
365+
return res, nil
359366
}
360367

361368
func (c *conn) QueryRowContext(ctx context.Context, query string, values []driver.Value) *singleRow {

chdb/driver/parquet_streaming_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func TestDBWithParquetStreamingConnection(t *testing.T) {
111111
if db.Ping() != nil {
112112
t.Fatalf("ping db fail, err: %s", err)
113113
}
114+
114115
rows, err := db.Query("select * from TestDBWithParquetConnectionStreaming;")
115116
if err != nil {
116117
t.Fatalf("exec create function fail, err: %s", err)

0 commit comments

Comments
 (0)