Skip to content

Commit 9890ff3

Browse files
committed
Fix memory leak when VNC exit
- Register client cleanup function when during initialization to ensure that twin_peer_t is freed properly when the client disconnects. - Properly release resources during VNC server shutdown by unreferencin current_fb and free the framebuffer allocated for tx->framebuffer Close #76
1 parent 16f7f9e commit 9890ff3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

backend/vnc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,18 @@ static bool _twin_vnc_work(void *closure)
102102
return true;
103103
}
104104

105+
static void _twin_vnc_client_cleanup(struct nvnc_client *client)
106+
{
107+
twin_peer_t *peer = nvnc_get_userdata(client);
108+
free(peer);
109+
nvnc_set_userdata(client, NULL, NULL);
110+
}
111+
105112
static void _twin_vnc_new_client(struct nvnc_client *client)
106113
{
107114
twin_peer_t *peer = malloc(sizeof(twin_peer_t));
108115
nvnc_set_userdata(client, peer, NULL);
116+
nvnc_set_client_cleanup_fn(client, _twin_vnc_client_cleanup);
109117
}
110118

111119
static void _twin_vnc_pointer_event(struct nvnc_client *client,
@@ -268,11 +276,12 @@ static void twin_vnc_exit(twin_context_t *ctx)
268276
return;
269277

270278
twin_vnc_t *tx = PRIV(ctx);
271-
279+
nvnc_fb_unref(tx->current_fb);
272280
nvnc_display_unref(tx->display);
273281
nvnc_close(tx->server);
274282
aml_unref(tx->aml);
275283

284+
free(tx->framebuffer);
276285
free(ctx->priv);
277286
free(ctx);
278287
}

0 commit comments

Comments
 (0)