Skip to Main Content

Berkeley DB Family

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Deleting Db handle causes assertion failure at debug mode (win32)

Osami-OracleNov 6 2007 — edited Nov 20 2007
Hi,

I have two newbie C++ questions to confirm.
The question is very simple but some inconsistency explained below makes me hesitate to answer back to my customer easily.

Q1:
Does instantiated Db handle need to be deleted after calling close()?

Following line causes assertion failure at last line in debug mode (though not in Release mode) with Win32 VC++ on BDB4.6.21;
<code>
Db *dbp=new Db(NULL, 0);
dbp->open(NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664);
dbp->close(0);
delete dbp;
<Result>
Debug Assertion Failed!
File: dbgheap.c
Line: 1132
Expression: _CrtIsValidHeapPointer(pUserData)

The result makes me think "delete" is not required as close() has already freed allocated memory for the Db handle. And it seems to be documented;

"The constructor allocates memory internally; calling the Db::close, Db::remove or Db::rename methods will free that memory."
"The Db handle may not be accessed again after Db::close is called, regardless of its return."

In fact, removing last line makes the code work.

Please confirm whether "delete" is not required or not.
Then this derives my second question..

Q2:
Sample codes provide both cases which has "delete" and which has not the line.
Why?

<Samples which have "delete">
\db-4.6.21\examples_cxx\TpcbExample.cpp
\db-4.6.21\examples_cxx\BtRecExample.cpp

<Samples which have NOT "delete">
\db-4.6.21\examples_cxx\txn_guide\TxnGuide.cpp


Thank you!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2007
Added on Nov 6 2007
6 comments
2,940 views