开发者

Re-Opening a BerkeleyDB database raises a Segmentation fault

开发者 https://www.devze.com 2023-04-04 22:46 出处:网络
In the following program, I open a BDB environment open a databaseDB_BTREE/DB_CREATE close the database

In the following program, I

  • open a BDB environment
  • open a database DB_BTREE/DB_CREATE
  • close the database
  • reopen the database as DB_UNKNOWN/DB_RDONLY ...

but it raises an segmentation fault.

Program received signal SIGSEGV, Segmentation fault.
0x00000000004008e4 in main (argc=2, argv=0x7fffffffe888) at testbdb.c:38
38                  if ((ret = dbp1->open(dbp1,

why ?

code:

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



int main(int argc,char** argv)
    {
    DB_ENV *dbenv=NULL;
        DB *dbp1=NULL;
        int ret;
        int i;
        if(argc!=2) return -1;

        if ((ret = db_env_create(&dbenv, 0)) != 0) {
            fprintf(stderr, "%s: %s\n", argv[0], db_strerror(ret));
            exit(-1);
        }


        if ((ret =
            dbenv->open(dbenv, argv[1], DB_CREATE | DB_INIT_MPOOL, 0)) != 0) {
            dbenv->err(dbenv, ret, "environment open: %s", argv[1]);
            exit(-1);
        }


        if ((ret = db_create(&dbp1, dbenv, 0)) != 0) {
            dbenv->err(dbenv, ret, "database create");
            exit(-1);
        }
        for( i=0;i<2;++i)
                {
                printf("open i=%d\n",i);
                if ((ret = dbp1->open(dbp1,
                        NULL,
                        "database1", "database1",
                        (i==0?DB_BTREE:DB_UNKNOWN),
                        (i==0?DB_CREATE:DB_RDONLY),
               开发者_如何学Python         0)) != 0) {
                    dbenv->err(dbenv, ret, "DB->open: database1");
                     exit(-1);
                    }

                dbp1->close(dbp1, 0);
                printf("close i=%d\n",i);
                }


    (void)dbenv->close(dbenv, 0);
    return 0;
    }


According to the documentation of the close() function "The DB handle may not be accessed again after DB->close() is called" which is what your loop is doing. That's probably a good place to start looking.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号