Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segfault when lua binding #12645

Open
Sookiep opened this issue May 11, 2024 · 0 comments
Open

segfault when lua binding #12645

Sookiep opened this issue May 11, 2024 · 0 comments

Comments

@Sookiep
Copy link

Sookiep commented May 11, 2024

I tried using Lua binding Rocksdb to call the C API in Rocksdb:

lua binding code:
`LUALIB_API int lrocksdb_open(lua_State *L) {
lrocksdb_options_t *o = lrocksdb_get_options(L, 1);
const char *path = luaL_checkstring(L, 2);
char *err = NULL;
rocksdb_t *db = rocksdb_open(o->options, path, &err);

if(err) {
luaL_error(L, err);
free(err);
return 0;
}

lrocksdb_t *d = (lrocksdb_t *) lua_newuserdata(L, sizeof(lrocksdb_t));
d->db = db;
d->options = o;
d->open = 1;
lrocksdb_setmeta(L, "db");
return 1;
}`

lua code:
local rocksdb = require 'rocksdb' local opts = rocksdb.options({ create_if_missing = true }) local rocksdbTest = rocksdb.open(opts, "rocks.db")

The test found that segfault occurred when the program ran to “rocksdb_t *db = rocksdb_open(o->options, path, &err);”, causing the process to crash. But strangely, there are occasional cases where Rocksdb is successfully opened and data is written, and it is uncertain whether it is due to incorrect binding or a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant