main: Fix ctl-server use after free

v0.8
Andri Yngvason 2023-12-10 19:02:55 +00:00
parent 830142701a
commit a7ed782bb9
1 changed files with 14 additions and 8 deletions

View File

@ -469,7 +469,8 @@ static void wayland_detach(struct wayvnc* self)
wl_display_disconnect(self->display); wl_display_disconnect(self->display);
self->display = NULL; self->display = NULL;
ctl_server_event_detached(self->ctl); if (self->ctl)
ctl_server_event_detached(self->ctl);
} }
void wayvnc_destroy(struct wayvnc* self) void wayvnc_destroy(struct wayvnc* self)
@ -1274,14 +1275,18 @@ static void client_destroy(void* obj)
nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d", nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d",
wayvnc->nr_clients); wayvnc->nr_clients);
struct ctl_server_client_info info = { if (wayvnc->ctl) {
.id = self->id, struct ctl_server_client_info info = {
.hostname = nvnc_client_get_hostname(self->nvnc_client), .id = self->id,
.username = nvnc_client_get_auth_username(self->nvnc_client), .hostname = nvnc_client_get_hostname(self->nvnc_client),
.seat = self->seat ? self->seat->name : NULL, .username = nvnc_client_get_auth_username(
}; self->nvnc_client),
.seat = self->seat ? self->seat->name : NULL,
};
ctl_server_event_disconnected(wayvnc->ctl, &info, wayvnc->nr_clients); ctl_server_event_disconnected(wayvnc->ctl, &info,
wayvnc->nr_clients);
}
if (wayvnc->nr_clients == 0 && wayvnc->display) { if (wayvnc->nr_clients == 0 && wayvnc->display) {
nvnc_log(NVNC_LOG_INFO, "Stopping screen capture"); nvnc_log(NVNC_LOG_INFO, "Stopping screen capture");
@ -1938,6 +1943,7 @@ int main(int argc, char* argv[])
screencopy_stop(&self.screencopy); screencopy_stop(&self.screencopy);
ctl_server_destroy(self.ctl); ctl_server_destroy(self.ctl);
self.ctl = NULL;
nvnc_display_unref(self.nvnc_display); nvnc_display_unref(self.nvnc_display);
nvnc_close(self.nvnc); nvnc_close(self.nvnc);