diff options
| author | Alexander Pickering <alex@cogarr.net> | 2020-09-18 23:28:29 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2020-09-18 23:28:29 -0400 |
| commit | 426acca4da85ccfb02abf3762a52151eb513ee54 (patch) | |
| tree | c6f82ad4a783160c78423a8dd46dd1b5c3e52fec /src | |
| parent | 7a80bf02bd93980d98613aaef1e9138d06dcf60c (diff) | |
| download | lua-nng-426acca4da85ccfb02abf3762a52151eb513ee54.tar.gz lua-nng-426acca4da85ccfb02abf3762a52151eb513ee54.tar.bz2 lua-nng-426acca4da85ccfb02abf3762a52151eb513ee54.zip | |
Fix a race condition
Fix a race condition that occures when garbage is collected in
the middle of a C function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lua-nng.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/lua-nng.c b/src/lua-nng.c index a57634e..649a022 100644 --- a/src/lua-nng.c +++ b/src/lua-nng.c @@ -27,7 +27,11 @@ #include <string.h> #include "lua-nng-aio.h" - +/*** +The lua binding of Nanomessage Next Generation +@namespace nng +*/ +@namespace nng #define OPEN(name)\ int lnng_ ## name ## _open(lua_State *L){\ nng_socket *s = (nng_socket*)lua_newuserdata(L,sizeof(nng_socket));\ @@ -143,8 +147,11 @@ int lnng_send(lua_State *L){ if(argc >= 3){ flags = luaL_checkinteger(L,3); } - lua_pop(L,argc); + //No garentee that *data is valid after it gets poped from the stack + //so we have to send it (which copies the value) before poping it from + //the stack. int err = nng_send(*sock, (void*)data, datasize, flags); + lua_pop(L,argc); if(err == 0){ lua_pushboolean(L,1); return 1; |
