Commit bc843844 authored by gwenn's avatar gwenn

Remove some deferred free calls

parent 3107a54d
...@@ -26,10 +26,10 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu ...@@ -26,10 +26,10 @@ func NewBackup(dst *Conn, dstDbName string, src *Conn, srcDbName string) (*Backu
} }
dname := C.CString(dstDbName) dname := C.CString(dstDbName)
sname := C.CString(srcDbName) sname := C.CString(srcDbName)
defer C.free(unsafe.Pointer(dname))
defer C.free(unsafe.Pointer(sname))
sb := C.sqlite3_backup_init(dst.db, dname, src.db, sname) sb := C.sqlite3_backup_init(dst.db, dname, src.db, sname)
C.free(unsafe.Pointer(sname))
C.free(unsafe.Pointer(dname))
if sb == nil { if sb == nil {
return nil, dst.error(C.sqlite3_errcode(dst.db), "backup init failed") return nil, dst.error(C.sqlite3_errcode(dst.db), "backup init failed")
} }
......
...@@ -59,13 +59,13 @@ func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobRead ...@@ -59,13 +59,13 @@ func (c *Conn) NewBlobReadWriter(db, table, column string, row int64) (*BlobRead
func (c *Conn) blobOpen(db, table, column string, row int64, write bool) (*C.sqlite3_blob, error) { func (c *Conn) blobOpen(db, table, column string, row int64, write bool) (*C.sqlite3_blob, error) {
zDb := C.CString(db) zDb := C.CString(db)
defer C.free(unsafe.Pointer(zDb))
zTable := C.CString(table) zTable := C.CString(table)
defer C.free(unsafe.Pointer(zTable))
zColumn := C.CString(column) zColumn := C.CString(column)
defer C.free(unsafe.Pointer(zColumn))
var bl *C.sqlite3_blob var bl *C.sqlite3_blob
rv := C.sqlite3_blob_open(c.db, zDb, zTable, zColumn, C.sqlite3_int64(row), btocint(write), &bl) rv := C.sqlite3_blob_open(c.db, zDb, zTable, zColumn, C.sqlite3_int64(row), btocint(write), &bl)
C.free(unsafe.Pointer(zColumn))
C.free(unsafe.Pointer(zTable))
C.free(unsafe.Pointer(zDb))
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
if bl != nil { if bl != nil {
C.sqlite3_blob_close(bl) C.sqlite3_blob_close(bl)
......
...@@ -103,8 +103,8 @@ type intArray struct { ...@@ -103,8 +103,8 @@ type intArray struct {
func (c *Conn) CreateIntArray(name string) (IntArray, error) { func (c *Conn) CreateIntArray(name string) (IntArray, error) {
var ia *C.sqlite3_intarray var ia *C.sqlite3_intarray
cname := C.CString(name) cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
rv := C.sqlite3_intarray_create(c.db, cname, &ia) rv := C.sqlite3_intarray_create(c.db, cname, &ia)
C.free(unsafe.Pointer(cname))
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return nil, Errno(rv) return nil, Errno(rv)
} }
......
...@@ -272,8 +272,8 @@ func (c *Conn) BusyTimeout(d time.Duration) error { ...@@ -272,8 +272,8 @@ func (c *Conn) BusyTimeout(d time.Duration) error {
// (See http://sqlite.org/c3ref/db_readonly.html) // (See http://sqlite.org/c3ref/db_readonly.html)
func (c *Conn) Readonly(dbName string) (bool, error) { func (c *Conn) Readonly(dbName string) (bool, error) {
cname := C.CString(dbName) cname := C.CString(dbName)
defer C.free(unsafe.Pointer(cname))
rv := C.sqlite3_db_readonly(c.db, cname) rv := C.sqlite3_db_readonly(c.db, cname)
C.free(unsafe.Pointer(cname))
if rv == -1 { if rv == -1 {
return false, c.specificError("%q is not the name of a database", dbName) return false, c.specificError("%q is not the name of a database", dbName)
} }
...@@ -566,8 +566,9 @@ func (c *Conn) exec(cmd string) error { ...@@ -566,8 +566,9 @@ func (c *Conn) exec(cmd string) error {
// FastExec executes one or many non-parameterized statement(s) (separated by semi-colon) with no control and no stmt cache. // FastExec executes one or many non-parameterized statement(s) (separated by semi-colon) with no control and no stmt cache.
func (c *Conn) FastExec(sql string) error { func (c *Conn) FastExec(sql string) error {
sqlstr := C.CString(sql) sqlstr := C.CString(sql)
defer C.free(unsafe.Pointer(sqlstr)) err := c.error(C.sqlite3_exec(c.db, sqlstr, nil, nil, nil))
return c.error(C.sqlite3_exec(c.db, sqlstr, nil, nil, nil)) C.free(unsafe.Pointer(sqlstr))
return err
} }
// Close closes a database connection and any dangling statements. // Close closes a database connection and any dangling statements.
......
...@@ -97,11 +97,11 @@ func (c *Conn) prepare(sql string, args ...interface{}) (*Stmt, error) { ...@@ -97,11 +97,11 @@ func (c *Conn) prepare(sql string, args ...interface{}) (*Stmt, error) {
return nil, errors.New("nil sqlite database") return nil, errors.New("nil sqlite database")
} }
sqlstr := C.CString(sql) sqlstr := C.CString(sql)
defer C.free(unsafe.Pointer(sqlstr))
var stmt *C.sqlite3_stmt var stmt *C.sqlite3_stmt
var tail *C.char var tail *C.char
// If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string. // If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string.
rv := C.sqlite3_prepare_v2(c.db, sqlstr, C.int(len(sql)+1), &stmt, &tail) rv := C.sqlite3_prepare_v2(c.db, sqlstr, C.int(len(sql)+1), &stmt, &tail)
C.free(unsafe.Pointer(sqlstr))
if rv != C.SQLITE_OK { if rv != C.SQLITE_OK {
return nil, c.error(rv, sql) return nil, c.error(rv, sql)
} }
...@@ -270,8 +270,8 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) { ...@@ -270,8 +270,8 @@ func (s *Stmt) BindParameterIndex(name string) (int, error) {
return index, nil return index, nil
} }
cname := C.CString(name) cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
index = int(C.sqlite3_bind_parameter_index(s.stmt, cname)) index = int(C.sqlite3_bind_parameter_index(s.stmt, cname))
C.free(unsafe.Pointer(cname))
if index == 0 { if index == 0 {
return index, s.specificError("invalid parameter name: %q", name) return index, s.specificError("invalid parameter name: %q", name)
} }
......
...@@ -357,8 +357,8 @@ func SetSoftHeapLimit(n int64) int64 { ...@@ -357,8 +357,8 @@ func SetSoftHeapLimit(n int64) int64 {
// (See http://sqlite.org/c3ref/complete.html) // (See http://sqlite.org/c3ref/complete.html)
func Complete(sql string) (bool, error) { func Complete(sql string) (bool, error) {
cs := C.CString(sql) cs := C.CString(sql)
defer C.free(unsafe.Pointer(cs))
rv := C.sqlite3_complete(cs) rv := C.sqlite3_complete(cs)
C.free(unsafe.Pointer(cs))
if rv == C.SQLITE_NOMEM { if rv == C.SQLITE_NOMEM {
return false, ErrNoMem return false, ErrNoMem
} }
...@@ -371,8 +371,8 @@ func Complete(sql string) (bool, error) { ...@@ -371,8 +371,8 @@ func Complete(sql string) (bool, error) {
// Applications can use the sqlite3_log(E,F,..) API to send new messages to the log, if desired, but this is discouraged. // Applications can use the sqlite3_log(E,F,..) API to send new messages to the log, if desired, but this is discouraged.
func Log(err /*Errno*/ int32, msg string) { func Log(err /*Errno*/ int32, msg string) {
cs := C.CString(msg) cs := C.CString(msg)
defer C.free(unsafe.Pointer(cs))
C.my_log(C.int(err), cs) C.my_log(C.int(err), cs)
C.free(unsafe.Pointer(cs))
} }
// Logger is the signature of SQLite logger implementation. // Logger is the signature of SQLite logger implementation.
......
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