From c5df6ca900cb445b88ede7e0ea3bb3a9042b5b6f Mon Sep 17 00:00:00 2001 From: Versus Void Date: Thu, 5 Oct 2017 20:01:56 +0000 Subject: [PATCH] Fix memory leaks --- backend/drm/backend.c | 2 +- backend/drm/drm.c | 13 +++++++++++++ include/rootston/desktop.h | 1 - include/rootston/input.h | 1 + render/gles2/renderer.c | 1 + rootston/input.c | 5 ++--- rootston/main.c | 1 + rootston/output.c | 1 - xwayland/xwm.c | 4 ++++ 9 files changed, 23 insertions(+), 6 deletions(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 468fca6e..d7e2e616 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -34,8 +34,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) { wlr_output_destroy(&conn->output); } - wlr_drm_renderer_finish(&drm->renderer); wlr_drm_resources_free(drm); + wlr_drm_renderer_finish(&drm->renderer); wlr_session_close_file(drm->session, drm->fd); wl_event_source_remove(drm->drm_event); list_free(drm->outputs); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 1a5fea9f..fc376b54 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -169,6 +169,19 @@ void wlr_drm_resources_free(struct wlr_drm_backend *drm) { drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id); } } + for (size_t i = 0; i < drm->num_planes; ++i) { + struct wlr_drm_plane *plane = &drm->planes[i]; + if (plane->cursor_bo) { + gbm_bo_destroy(plane->cursor_bo); + } + if (plane->wlr_tex) { + wlr_texture_destroy(plane->wlr_tex); + } + if (plane->wlr_rend) { + wlr_renderer_destroy(plane->wlr_rend); + } + } + free(drm->crtcs); free(drm->planes); } diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 91ac87b7..0d641848 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -16,7 +16,6 @@ struct roots_output { struct roots_desktop *desktop; struct wlr_output *wlr_output; struct wl_listener frame; - struct wl_listener resolution; struct timespec last_frame; struct wl_list link; }; diff --git a/include/rootston/input.h b/include/rootston/input.h index 6161eb7a..f7cd2929 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -76,6 +76,7 @@ struct roots_input { // TODO: multiseat, multicursor struct wlr_cursor *cursor; + struct wlr_xcursor_theme *theme; struct wlr_xcursor *xcursor; struct wlr_seat *wl_seat; diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index f0c724e4..d6c22ebe 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -95,6 +95,7 @@ static void init_default_shaders() { } wlr_log(L_DEBUG, "Compiled default shaders"); + shaders.initialized = true; return; error: wlr_log(L_ERROR, "Failed to set up default shaders!"); diff --git a/rootston/input.c b/rootston/input.c index 9700b840..86a87e24 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -79,9 +79,8 @@ struct roots_input *input_create(struct roots_server *server, input->config = config; input->server = server; - struct wlr_xcursor_theme *theme; - assert(theme = wlr_xcursor_theme_load("default", 16)); - assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr")); + assert(input->theme = wlr_xcursor_theme_load("default", 16)); + assert(input->xcursor = wlr_xcursor_theme_get_cursor(input->theme, "left_ptr")); assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0")); wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD diff --git a/rootston/main.c b/rootston/main.c index 65a06a2f..5a60000c 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -43,5 +43,6 @@ int main(int argc, char **argv) { setenv("WAYLAND_DISPLAY", socket, true); wl_display_run(server.wl_display); + wlr_backend_destroy(server.backend); return 0; } diff --git a/rootston/output.c b/rootston/output.c index 14d1783e..bbc957aa 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -147,6 +147,5 @@ void output_remove_notify(struct wl_listener *listener, void *data) { // sample->compositor); wl_list_remove(&output->link); wl_list_remove(&output->frame.link); - wl_list_remove(&output->resolution.link); free(output); } diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 2038ff0f..39989672 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -83,6 +83,10 @@ static void wlr_xwayland_surface_destroy(struct wlr_xwayland_surface *surface) { } list_free(surface->state); free(surface->window_type); + free(surface->protocols); + free(surface->class); + free(surface->instance); + free(surface->title); free(surface); }