Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> OCI error handle is freed only with environment handle

OCI error handle is freed only with environment handle

From: <amit_s_at_trivnet.com>
Date: Wed, 03 Feb 1999 15:15:16 GMT
Message-ID: <799p5q$fu9$1@nnrp1.dejanews.com>


While writing an application that keeps open connections to oracle database, I ran into an interesting problem:

It seems as the error handle is not freed until its related environment handle is freed,
although using OCIHandleFree with the error handle. I have written a short OCI program to show it:

consider two functions:

1.

void select1(OCIEnv *envhp, OCISvcCtx *svchp) {

	OCIStmt *stmthp;
	OCIError *errhp;

	(void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp,
OCI_HTYPE_ERROR,
						   (size_t) 0, (dvoid **) 0);

	checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,

OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));

	checkerr(errhp, OCIStmtPrepare(stmthp, errhp, sel,
								   (ub4)
strlen((char *) sel),
								   (ub4)

OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
	status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,

(CONST OCISnapshot *)
NULL,
(OCISnapshot *) NULL,

OCI_DEFAULT);  checkerr(errhp, OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT));  checkerr(errhp, OCIHandleFree((dvoid *) errhp, OCI_HTYPE_ERROR));  }

2.

void select2(OCIEnv *envhp, OCISvcCtx *svchp, OCIError *errhp) {

        OCIStmt *stmthp;

        checkerr(errhp, OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &stmthp,

OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));

	checkerr(errhp, OCIStmtPrepare(stmthp, errhp, sel,
								   (ub4)
strlen((char *) sel),
								   (ub4)

OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT));
	status = OCIStmtExecute(svchp, stmthp, errhp, (ub4) 1, (ub4) 0,

(CONST OCISnapshot *)
NULL,
(OCISnapshot *) NULL,

OCI_DEFAULT);  checkerr(errhp, OCIHandleFree((dvoid *) stmthp, OCI_HTYPE_STMT));  }

Assume all necessary handles are allocated and freed in the main function. 'checkerr' is checking errors.
When calling 'select1' in an endless loop - a memory leak occur. When calling 'select2' in an endless loop - the memory leak does not occur.

Does anyone know the reason?

Thanks, Amit.

-----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own Received on Wed Feb 03 1999 - 09:15:16 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US