Skip to content

Commit

Permalink
bindings/lua: take a reference on watch directory
Browse files Browse the repository at this point in the history
Problem: lua segfaults when garbage collecting
kvsdir_t.

When a kvs_watch() callback receives a kvsdir_t
argument, it is only valid for the duration of the
callback.  When instantiating a directory as a Lua table
that persists after the callback, it looks like we need
to call kvsdir_incref() on the directory to avoid illegal
access and/or double free during garbage collection.
  • Loading branch information
garlick committed Jul 19, 2017
1 parent e2968e7 commit 9b2c239
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/bindings/lua/flux-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ static int kvswatch_cb_common (const char *key, kvsdir_t *dir,
assert (lua_isuserdata (L, -1));

if (dir) {
lua_push_kvsdir (L, dir);
lua_push_kvsdir_external (L, dir); // take a reference
lua_pushnil (L);
}
else if (val) {
Expand Down

0 comments on commit 9b2c239

Please sign in to comment.