Last active
July 22, 2023 05:18
-
-
Save jnwatson/86b43b0515fe552a087d741d4ab43922 to your computer and use it in GitHub Desktop.
LMDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc -ggdb -std=c11 -Wall -I ~/proj/py-lmdb/lib lmdb_crash1.c ~/proj/py-lmdb/lib/{mdb.c,midl.c} -lpthread -o mdb_c_exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(gdb) run | |
Starting program: /home/nic/proj/lmdb_crash_test/mdb_c_exe | |
[Thread debugging using libthread_db enabled] | |
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". | |
Running LMDB 0.9.21: (June 1, 2017) | |
Program received signal SIGSEGV, Segmentation fault. | |
0x00000000004146d5 in mdb_dbi_open (txn=0x61e810, name=0x41a551 "another_db", flags=262144, dbi=0x7fffffffd74c) at /home/nic/proj/py-lmdb/lib/mdb.c:9772 | |
9772 WITH_CURSOR_TRACKING(mc, | |
(gdb) bt | |
#0 0x00000000004146d5 in mdb_dbi_open (txn=0x61e810, name=0x41a551 "another_db", flags=262144, dbi=0x7fffffffd74c) at /home/nic/proj/py-lmdb/lib/mdb.c:9772 | |
#1 0x0000000000401b94 in cause_crash () at lmdb_crash1.c:31 | |
#2 0x0000000000401c3d in main (argc=1, argv=0x7fffffffd878) at lmdb_crash1.c:49 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "lmdb.h" | |
void cause_crash() | |
{ | |
MDB_env *env; | |
MDB_txn *txn; | |
MDB_dbi dbi; | |
int rc; | |
int line_fail = 0; | |
rc = mdb_env_create(&env); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
rc = mdb_env_open(env, "foo.lmdb", 0, 0777); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
mdb_env_close(env); | |
rc = mdb_env_create(&env); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
rc = mdb_env_set_maxdbs(env, 10); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
rc = mdb_env_open(env, "foo.lmdb", MDB_RDONLY, 0777); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
/* Crashes on next line. */ | |
rc = mdb_dbi_open(txn, "another_db", MDB_CREATE, &dbi); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
rc = mdb_txn_commit(txn); | |
if (rc) { line_fail = __LINE__; goto fail; } | |
mdb_dbi_close(env, dbi); | |
mdb_env_close(env); | |
return; | |
fail: | |
printf("Failed with error %d on line %d\n", rc, line_fail); | |
} | |
int main(int argc, char **argv) | |
{ | |
printf("Running %s\n", MDB_VERSION_STRING); | |
cause_crash(); | |
printf("Didn't crash!\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment