dbTalk Databases Forums  

handle->close() ; error "SEGMENTATION FAULT"

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss handle->close() ; error "SEGMENTATION FAULT" in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
intmail01@gmail.com
 
Posts: n/a

Default handle->close() ; error "SEGMENTATION FAULT" - 11-21-2005 , 06:10 AM






Hello,

I am writting here because I would like to know why my code cause
an "segmentation fault" with berkeley db library.
Creating handle works well but closing it.


#include <db.h>
#include <stdio.h>

DB *h_journal;

/****************************************
*****************************************
** CREATE handle **
** **
*****************************************
*****************************************/
int create_handle(DB *db_handle, u_int32_t flags)
{
int ret;

ret = db_create(&db_handle, NULL, 0);
if (ret != 0)
{
db_handle->close(db_handle, 0);
return (ret);
}
else
{
ret = db_handle->set_flags(db_handle, flags);
if (ret != 0) return (ret);
}
return (0);
}

/****************************************
*****************************************
** CLOSE a handle **
** **
*****************************************
*****************************************/
int close_handle(DB *db_handle)
{
db_handle->close(db_handle, 0);
}

void main(void)
{
if ( create_handle(h_journal, DB_DUPSORT) )
printf("\n--Error creating handle\n"); // This line works well
close_handle(h_journal); // This line makes an "SEGMENTATION FAULT"
error
}


Reply With Quote
  #2  
Old   
Michael Cahill
 
Posts: n/a

Default Re: handle->close() ; error "SEGMENTATION FAULT" - 11-21-2005 , 07:12 AM






Hi,

The problem is pointer confusion -- when you call db_create:

ret = db_create(&db_handle, NULL, 0);

this will update db_handle on the stack, but won't update the h_journal
global variable. To fix this, you'll need to make your create_handle
function take a DB **, and pass &h_journal from main().

Regards,
Michael.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.