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

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;