mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
Fix handle register when slot[0] is null will segmentation fault (#1574)
This commit is contained in:
10
examples/config.handle
Normal file
10
examples/config.handle
Normal 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"
|
||||||
@@ -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 *));
|
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 *));
|
memset(new_slot, 0, s->slot_size * 2 * sizeof(struct skynet_context *));
|
||||||
for (i=0;i<s->slot_size;i++) {
|
for (i=0;i<s->slot_size;i++) {
|
||||||
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
|
if (s->slot[i]) {
|
||||||
assert(new_slot[hash] == NULL);
|
int hash = skynet_context_handle(s->slot[i]) & (s->slot_size * 2 - 1);
|
||||||
new_slot[hash] = s->slot[i];
|
assert(new_slot[hash] == NULL);
|
||||||
|
new_slot[hash] = s->slot[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
skynet_free(s->slot);
|
skynet_free(s->slot);
|
||||||
s->slot = new_slot;
|
s->slot = new_slot;
|
||||||
|
|||||||
33
test/testhandle.lua
Normal file
33
test/testhandle.lua
Normal 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
|
||||||
Reference in New Issue
Block a user