mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-30 02:31:53 +08:00
fix memory leak caused by returning noRows{}/II, updates #43
This commit is contained in:
23
sqlite.go
23
sqlite.go
@@ -34,6 +34,7 @@ var (
|
||||
_ driver.Queryer = (*conn)(nil)
|
||||
_ driver.Result = (*result)(nil)
|
||||
_ driver.Rows = (*rows)(nil)
|
||||
_ driver.Rows = (*noRows)(nil)
|
||||
_ driver.RowsColumnTypeDatabaseTypeName = (*rows)(nil)
|
||||
_ driver.RowsColumnTypeLength = (*rows)(nil)
|
||||
_ driver.RowsColumnTypeNullable = (*rows)(nil)
|
||||
@@ -621,7 +622,6 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
||||
if r != nil {
|
||||
r.Close()
|
||||
}
|
||||
|
||||
if r, err = newRows(s.c, pstmt, allocs, false); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -630,9 +630,9 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
||||
return nil
|
||||
case sqlite3.SQLITE_DONE:
|
||||
if r == nil {
|
||||
r = &noRows{c: s.c, pstmt: pstmt, allocs: allocs}
|
||||
pstmt = 0
|
||||
r, err = newRows(s.c, pstmt, allocs, true)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// nop
|
||||
@@ -663,6 +663,23 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
||||
return r, err
|
||||
}
|
||||
|
||||
type noRows struct {
|
||||
allocs []uintptr
|
||||
c *conn
|
||||
pstmt uintptr
|
||||
}
|
||||
|
||||
func (r *noRows) Columns() []string { return nil }
|
||||
func (r *noRows) Next([]driver.Value) error { return io.EOF }
|
||||
|
||||
func (r *noRows) Close() error {
|
||||
for _, v := range r.allocs {
|
||||
r.c.free(v)
|
||||
}
|
||||
r.allocs = nil
|
||||
return r.c.finalize(r.pstmt)
|
||||
}
|
||||
|
||||
type tx struct {
|
||||
c *conn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user