Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak when VNC exit #82

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ static void apps_flower_start(twin_screen_t *screen, int x, int y, int w, int h)
draw_flower(path, D(3), 5);
twin_paint_path(pixmap, 0xffe2d2d2, path);
twin_path_destroy(stroke);
twin_path_destroy(path);
twin_window_show(window);
}

Expand Down
11 changes: 10 additions & 1 deletion backend/vnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,18 @@ static bool _twin_vnc_work(void *closure)
return true;
}

static void _twin_vnc_client_cleanup(struct nvnc_client *client)
{
twin_peer_t *peer = nvnc_get_userdata(client);
free(peer);
nvnc_set_userdata(client, NULL, NULL);
}

static void _twin_vnc_new_client(struct nvnc_client *client)
{
twin_peer_t *peer = malloc(sizeof(twin_peer_t));
nvnc_set_userdata(client, peer, NULL);
nvnc_set_client_cleanup_fn(client, _twin_vnc_client_cleanup);
}

static void _twin_vnc_pointer_event(struct nvnc_client *client,
Expand Down Expand Up @@ -268,11 +276,12 @@ static void twin_vnc_exit(twin_context_t *ctx)
return;

twin_vnc_t *tx = PRIV(ctx);

nvnc_fb_unref(tx->current_fb);
nvnc_display_unref(tx->display);
nvnc_close(tx->server);
aml_unref(tx->aml);

free(tx->framebuffer);
free(ctx->priv);
free(ctx);
}
Expand Down