Fix handle register when slot[0] is null will segmentation fault (#1574)

This commit is contained in:
涵曦
2022-04-13 22:36:47 +08:00
committed by GitHub
parent e37eb3cba0
commit ee103e97cd
3 changed files with 48 additions and 3 deletions

10
examples/config.handle Normal file
View File

@@ -0,0 +1,10 @@
include "config.path"
thread = 8
logger = "skynet.log"
logpath = "."
harbor = 0
start = "testhandle" -- main script
bootstrap = "snlua bootstrap" -- The service for bootstrap
cpath = root.."cservice/?.so"
--daemon = "./skynet.pid"

View File

@@ -60,9 +60,11 @@ skynet_handle_register(struct skynet_context *ctx) {
struct skynet_context ** new_slot = skynet_malloc(s->slot_size * 2 * sizeof(struct skynet_context *));
memset(new_slot, 0, s->slot_size * 2 * sizeof(struct skynet_context *));
for (i=0;i<s->slot_size;i++) {
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
assert(new_slot[hash] == NULL);
new_slot[hash] = s->slot[i];
if (s->slot[i]) {
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
assert(new_slot[hash] == NULL);
new_slot[hash] = s->slot[i];
}
}
skynet_free(s->slot);
s->slot = new_slot;

33
test/testhandle.lua Normal file
View File

@@ -0,0 +1,33 @@
local skynet = require "skynet"
require "skynet.manager"
local mod = ...
if mod == "slave" then
skynet.start(function()
skynet.error("addr:", skynet.self())
end)
else
skynet.start(function()
skynet.newservice("debug_console",8000)
skynet.error("master addr:", skynet.self())
skynet.newservice("testhandle", "slave")
skynet.newservice("testhandle", "slave")
skynet.newservice("testhandle", "slave")
skynet.newservice("testhandle", "slave")
skynet.newservice("testhandle", "slave")
skynet.newservice("testhandle", "slave")
while true do
local addr = skynet.newservice("testhandle", "slave")
skynet.kill(addr)
if addr > 0xfffff0 then
break
end
end
end)
end