Bugfix: mc.close may reference an invalid pointer. See pr #220

This commit is contained in:
Cloud Wu
2015-01-05 12:17:57 +08:00
parent 52134f9e57
commit ee3f9c6ecd
2 changed files with 12 additions and 7 deletions

View File

@@ -83,7 +83,7 @@ mc_unpacklocal(lua_State *L) {
if (sz != sizeof(*pack)) {
return luaL_error(L, "Invalid multicast package size %d", sz);
}
lua_settop(L, 1);
lua_pushlightuserdata(L, *pack);
lua_pushlightuserdata(L, (*pack)->data);
lua_pushunsigned(L, (*pack)->size);
return 3;
@@ -92,6 +92,8 @@ mc_unpacklocal(lua_State *L) {
/*
lightuserdata struct mc_package **
integer reference
return mc_package *
*/
static int
mc_bindrefer(lua_State *L) {
@@ -102,16 +104,17 @@ mc_bindrefer(lua_State *L) {
}
(*pack)->reference = ref;
return 0;
lua_pushlightuserdata(L, *pack);
return 1;
}
/*
lightuserdata struct mc_package **
lightuserdata struct mc_package *
*/
static int
mc_closelocal(lua_State *L) {
struct mc_package **ptr = lua_touserdata(L,1);
struct mc_package *pack = *ptr;
struct mc_package *pack = lua_touserdata(L,1);
int ref = __sync_sub_and_fetch(&pack->reference, 1);
if (ref <= 0) {