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 468fca6eb..d7e2e6167 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 1a5fea9fb..fc376b549 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 91ac87b70..0d6418481 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 6161eb7a3..f7cd29298 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 f0c724e49..d6c22ebe6 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 9700b8406..86a87e24f 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 65a06a2f0..5a60000cf 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 14d1783e0..bbc957aa5 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 2038ff0fb..399896729 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); }