mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
memory leak bugfix in multicast, See issue #519
This commit is contained in:
@@ -60,18 +60,6 @@ mc_packremote(lua_State *L) {
|
|||||||
return pack(L, msg, size);
|
return pack(L, msg, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
mc_packstring(lua_State *L) {
|
|
||||||
size_t size;
|
|
||||||
const char * msg = luaL_checklstring(L, 1, &size);
|
|
||||||
if (size != (uint32_t)size) {
|
|
||||||
return luaL_error(L, "string is too long");
|
|
||||||
}
|
|
||||||
void * data = skynet_malloc(size);
|
|
||||||
memcpy(data, msg, size);
|
|
||||||
return pack(L, data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
lightuserdata struct mc_package **
|
lightuserdata struct mc_package **
|
||||||
integer size (must be sizeof(struct mc_package *)
|
integer size (must be sizeof(struct mc_package *)
|
||||||
@@ -82,7 +70,7 @@ static int
|
|||||||
mc_unpacklocal(lua_State *L) {
|
mc_unpacklocal(lua_State *L) {
|
||||||
struct mc_package ** pack = lua_touserdata(L,1);
|
struct mc_package ** pack = lua_touserdata(L,1);
|
||||||
int sz = luaL_checkinteger(L,2);
|
int sz = luaL_checkinteger(L,2);
|
||||||
if (sz != sizeof(*pack)) {
|
if (sz != sizeof(pack)) {
|
||||||
return luaL_error(L, "Invalid multicast package size %d", sz);
|
return luaL_error(L, "Invalid multicast package size %d", sz);
|
||||||
}
|
}
|
||||||
lua_pushlightuserdata(L, *pack);
|
lua_pushlightuserdata(L, *pack);
|
||||||
@@ -108,6 +96,8 @@ mc_bindrefer(lua_State *L) {
|
|||||||
|
|
||||||
lua_pushlightuserdata(L, *pack);
|
lua_pushlightuserdata(L, *pack);
|
||||||
|
|
||||||
|
skynet_free(pack);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +151,6 @@ luaopen_multicast_core(lua_State *L) {
|
|||||||
{ "bind", mc_bindrefer },
|
{ "bind", mc_bindrefer },
|
||||||
{ "close", mc_closelocal },
|
{ "close", mc_closelocal },
|
||||||
{ "remote", mc_remote },
|
{ "remote", mc_remote },
|
||||||
{ "packstring", mc_packstring },
|
|
||||||
{ "packremote", mc_packremote },
|
{ "packremote", mc_packremote },
|
||||||
{ "nextid", mc_nextid },
|
{ "nextid", mc_nextid },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
|
|||||||
@@ -78,13 +78,13 @@ local function publish(c , source, pack, size)
|
|||||||
|
|
||||||
local group = channel[c]
|
local group = channel[c]
|
||||||
if group == nil or next(group) == nil then
|
if group == nil or next(group) == nil then
|
||||||
-- dead channel, delete the pack. mc.bind returns the pointer in pack
|
-- dead channel, delete the pack. mc.bind returns the pointer in pack and free the pack (struct mc_package **)
|
||||||
local pack = mc.bind(pack, 1)
|
local pack = mc.bind(pack, 1)
|
||||||
mc.close(pack)
|
mc.close(pack)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mc.bind(pack, channel_n[c])
|
local msg = skynet.tostring(pack, size) -- copy (pack,size) to a string
|
||||||
local msg = skynet.tostring(pack, size)
|
mc.bind(pack, channel_n[c]) -- mc.bind will free the pack(struct mc_package **)
|
||||||
for k in pairs(group) do
|
for k in pairs(group) do
|
||||||
-- the msg is a pointer to the real message, publish pointer in local is ok.
|
-- the msg is a pointer to the real message, publish pointer in local is ok.
|
||||||
skynet.redirect(k, source, "multicast", c , msg)
|
skynet.redirect(k, source, "multicast", c , msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user