Commit 0f8d5237 authored by gwenn's avatar gwenn

Avoid double-free

parent 55d338fe
...@@ -112,10 +112,13 @@ func (b *Backup) Close() error { ...@@ -112,10 +112,13 @@ func (b *Backup) Close() error {
if b == nil { if b == nil {
return errors.New("nil sqlite backup") return errors.New("nil sqlite backup")
} }
rv := C.sqlite3_backup_finish(b.sb) if b.sb == nil {
return nil
}
rv := C.sqlite3_backup_finish(b.sb) // must be called only once
b.sb = nil
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return b.dst.error(rv, "backup finish failed") return b.dst.error(rv, "backup finish failed")
} }
b.sb = nil
return nil return nil
} }
...@@ -84,11 +84,14 @@ func (r *BlobReader) Close() error { ...@@ -84,11 +84,14 @@ func (r *BlobReader) Close() error {
if r == nil { if r == nil {
return errors.New("nil sqlite blob") return errors.New("nil sqlite blob")
} }
rv := C.sqlite3_blob_close(r.bl) if r.bl == nil {
return nil
}
rv := C.sqlite3_blob_close(r.bl) // must be called only once
r.bl = nil
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return r.c.error(rv, "BlobReader.Close") return r.c.error(rv, "BlobReader.Close")
} }
r.bl = nil
return nil return nil
} }
......
...@@ -1167,7 +1167,7 @@ func (s *Stmt) finalize() error { ...@@ -1167,7 +1167,7 @@ func (s *Stmt) finalize() error {
Log(C.SQLITE_MISUSE, "sqlite statement with already closed database connection") Log(C.SQLITE_MISUSE, "sqlite statement with already closed database connection")
return errors.New("sqlite statement with already closed database connection") return errors.New("sqlite statement with already closed database connection")
} }
rv := C.sqlite3_finalize(s.stmt) rv := C.sqlite3_finalize(s.stmt) // must be called only once
s.stmt = nil s.stmt = nil
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
Log(int32(rv), "error while finalizing Stmt") Log(int32(rv), "error while finalizing Stmt")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment