Skip to content

Commit

Permalink
Do not free stmt.ocistmt - fixes #222
Browse files Browse the repository at this point in the history
  • Loading branch information
tgulacsi committed Sep 19, 2017
1 parent dd5b9d2 commit 1bb2ff5
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,10 @@ func (stmt *Stmt) close() (err error) {
stmt.logF(true, "PANIC %v", err)
errs.PushBack(err)
}
// free ocistmt to release cursor on server
// OCIStmtRelease must be called with OCIStmtPrepare2
// See https://docs.oracle.com/database/121/LNOCI/oci09adv.htm#LNOCI16655
stmt.Lock()
env := stmt.Env()
ocistmt := stmt.ocistmt
r := C.OCIStmtRelease(
ocistmt, // OCIStmt *stmthp
env.ocierr, // OCIError *errhp,
nil, // const OraText *key
C.ub4(0), // ub4 keylen
C.OCI_DEFAULT, // ub4 mode
)
stmt.Unlock()
if r == C.OCI_ERROR {
errs.PushBack(errE(env.ociError()))
}

C.OCIHandleFree(unsafe.Pointer(ocistmt), C.OCI_HTYPE_STMT)

stmt.SetCfg(StmtCfg{})
stmt.Lock()
stmt.stringPtrBufferSize = 0
stmt.env.Store((*Env)(nil))
stmt.ses = nil
Expand All @@ -185,6 +167,26 @@ func (stmt *Stmt) close() (err error) {
stmt.openRsets.clear()
_drv.stmtPool.Put(stmt)
stmt.Unlock()
stmt.SetCfg(StmtCfg{})

if ocistmt != nil {
// free ocistmt to release cursor on server
// OCIStmtRelease must be called with OCIStmtPrepare2
// See https://docs.oracle.com/database/121/LNOCI/oci09adv.htm#LNOCI16655
r := C.OCIStmtRelease(
ocistmt, // OCIStmt *stmthp
env.ocierr, // OCIError *errhp,
nil, // const OraText *key
C.ub4(0), // ub4 keylen
C.OCI_DEFAULT, // ub4 mode
)
if r == C.OCI_ERROR {
errs.PushBack(errE(env.ociError()))
// Sometimes panics if free unconditionally - see #222.
// https://github.com/rana/ora/issues/222
C.OCIHandleFree(unsafe.Pointer(ocistmt), C.OCI_HTYPE_STMT)
}
}

multiErr := newMultiErrL(errs)
if multiErr != nil {
Expand Down

0 comments on commit 1bb2ff5

Please sign in to comment.