mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-11-02 21:55:04 +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.Queryer = (*conn)(nil)
|
||||||
_ driver.Result = (*result)(nil)
|
_ driver.Result = (*result)(nil)
|
||||||
_ driver.Rows = (*rows)(nil)
|
_ driver.Rows = (*rows)(nil)
|
||||||
|
_ driver.Rows = (*noRows)(nil)
|
||||||
_ driver.RowsColumnTypeDatabaseTypeName = (*rows)(nil)
|
_ driver.RowsColumnTypeDatabaseTypeName = (*rows)(nil)
|
||||||
_ driver.RowsColumnTypeLength = (*rows)(nil)
|
_ driver.RowsColumnTypeLength = (*rows)(nil)
|
||||||
_ driver.RowsColumnTypeNullable = (*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 {
|
if r != nil {
|
||||||
r.Close()
|
r.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if r, err = newRows(s.c, pstmt, allocs, false); err != nil {
|
if r, err = newRows(s.c, pstmt, allocs, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -630,9 +630,9 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
|||||||
return nil
|
return nil
|
||||||
case sqlite3.SQLITE_DONE:
|
case sqlite3.SQLITE_DONE:
|
||||||
if r == nil {
|
if r == nil {
|
||||||
|
r = &noRows{c: s.c, pstmt: pstmt, allocs: allocs}
|
||||||
pstmt = 0
|
pstmt = 0
|
||||||
r, err = newRows(s.c, pstmt, allocs, true)
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// nop
|
// nop
|
||||||
@@ -663,6 +663,23 @@ func (s *stmt) query(ctx context.Context, args []driver.NamedValue) (r driver.Ro
|
|||||||
return r, err
|
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 {
|
type tx struct {
|
||||||
c *conn
|
c *conn
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user