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!

Memory leak with DB_PRIVATE environment

560973Feb 9 2007 — edited Feb 11 2007
I am using the C API of BerkeleyDB 4.4.20 under Win32. I seem to be encountering a number of memory leaks when using DB_PRIVATE in DB_ENV::open. Is this a known issue?

For example, if DB_LOG_INMEMORY is set, then the __db_filestart struct allocated in __log_inmem_newfile() is never freed. I can fix this by adding the following into __log_dbenv_refresh() within the DB_ENV_PRIVATE check.

 struct __db_filestart *filestart;
 while ((filestart = SH_TAILQ_FIRST(&lp->logfiles, __db_filestart)) != NULL) {
  SH_TAILQ_REMOVE(&lp->logfiles, filestart, links, __db_filestart);
  __db_shalloc_free(reginfo, filestart);
 }

If I open an in-memory database, I encounter even more leaks. It looks like the MPOOLFILE allocated under __fop_inmem_create() is never freed. It wasn't obvious to me where the fix for this should go. I'm afraid to actually do database operations for fear of what I'll find then.

Here is my test setup.

  void leakTest()
   {
   u_int32_t envFlags = DB_LOG_INMEMORY;
   u_int32_t envOpenFlags =
   DB_CREATE |
   DB_INIT_MPOOL |
   DB_INIT_TXN |
   DB_PRIVATE;
  
   DB_ENV* dbEnv = NULL;
   assert( 0 == ::db_env_create( &dbEnv, 0 ) );
   assert( 0 == dbEnv->set_flags( dbEnv, envFlags, 1 ) );
   assert( 0 == dbEnv->open( dbEnv, "", envOpenFlags, 0 ) );
  
  #if 1
   const char* file = NULL;
   u_int32_t openFlags = DB_CREATE;
   DB* dbh = NULL;
   assert( 0 == ::db_create( &dbh, dbEnv, 0 ) );
   assert( 0 == dbh->open( dbh, NULL, file, "dbname", DB_BTREE, openFlags, 0644 ) );
   assert( 0 == dbh->close( dbh, 0 ) );
  #endif
  
   assert( 0 == dbEnv->close( dbEnv, 0 ) );
   _CrtDumpMemoryLeaks();
   }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 11 2007
Added on Feb 9 2007
1 comment
1,144 views