Skip to content

Commit

Permalink
main: Fix ctl-server use after free
Browse files Browse the repository at this point in the history
  • Loading branch information
any1 committed Dec 10, 2023
1 parent 8301427 commit a7ed782
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ static void wayland_detach(struct wayvnc* self)
wl_display_disconnect(self->display);
self->display = NULL;

ctl_server_event_detached(self->ctl);
if (self->ctl)
ctl_server_event_detached(self->ctl);
}

void wayvnc_destroy(struct wayvnc* self)
Expand Down Expand Up @@ -1274,14 +1275,18 @@ static void client_destroy(void* obj)
nvnc_log(NVNC_LOG_DEBUG, "Client disconnected, new client count: %d",
wayvnc->nr_clients);

struct ctl_server_client_info info = {
.id = self->id,
.hostname = nvnc_client_get_hostname(self->nvnc_client),
.username = nvnc_client_get_auth_username(self->nvnc_client),
.seat = self->seat ? self->seat->name : NULL,
};
if (wayvnc->ctl) {
struct ctl_server_client_info info = {
.id = self->id,
.hostname = nvnc_client_get_hostname(self->nvnc_client),
.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) {
nvnc_log(NVNC_LOG_INFO, "Stopping screen capture");
Expand Down Expand Up @@ -1938,6 +1943,7 @@ int main(int argc, char* argv[])
screencopy_stop(&self.screencopy);

ctl_server_destroy(self.ctl);
self.ctl = NULL;

nvnc_display_unref(self.nvnc_display);
nvnc_close(self.nvnc);
Expand Down

0 comments on commit a7ed782

Please sign in to comment.