From 9043c79ac289e675d22cfee7c6a3ebe2eb79e61b Mon Sep 17 00:00:00 2001 From: jeon Date: Mon, 21 Dec 2020 16:30:25 +0900 Subject: [PATCH] fix svace issues - add null check - free allocated memory Change-Id: Ic609fce530c41e877311d83764c178cfd73bfeb4 --- src/lib/desktop-shell/desktop-shell-internal.h | 3 +++ src/lib/desktop-shell/wl-shell.c | 10 ++++++---- src/lib/desktop-shell/xdg-shell.c | 10 ++++++---- src/lib/devicemgr/pepper-devicemgr.c | 1 + src/lib/pepper/utils.c | 1 + src/lib/wayland/wayland-output.c | 11 +++++++++++ 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/lib/desktop-shell/desktop-shell-internal.h b/src/lib/desktop-shell/desktop-shell-internal.h index 8c5bbc2..31ce1a7 100644 --- a/src/lib/desktop-shell/desktop-shell-internal.h +++ b/src/lib/desktop-shell/desktop-shell-internal.h @@ -68,6 +68,9 @@ struct desktop_shell { pepper_surface_t *cursor_surface; pepper_view_t *cursor_view; + struct wl_global *wl_shell_global; + struct wl_global *xdg_shell_global; + /* input device add/remove listeners */ pepper_event_listener_t *input_device_add_listener; diff --git a/src/lib/desktop-shell/wl-shell.c b/src/lib/desktop-shell/wl-shell.c index c2cbe49..6555ea4 100644 --- a/src/lib/desktop-shell/wl-shell.c +++ b/src/lib/desktop-shell/wl-shell.c @@ -217,10 +217,9 @@ pepper_bool_t init_wl_shell(desktop_shell_t *shell) { struct wl_display *display = pepper_compositor_get_display(shell->compositor); - struct wl_global *global; - global = wl_global_create(display, &wl_shell_interface, 1, shell, bind_shell); - if (!global) + shell->wl_shell_global = wl_global_create(display, &wl_shell_interface, 1, shell, bind_shell); + if (!shell->wl_shell_global) return PEPPER_FALSE; return PEPPER_TRUE; @@ -229,5 +228,8 @@ init_wl_shell(desktop_shell_t *shell) void fini_wl_shell(desktop_shell_t *shell) { - /* TODO */ + if (shell->wl_shell_global) { + wl_global_destroy(shell->wl_shell_global); + shell->wl_shell_global = NULL; + } } diff --git a/src/lib/desktop-shell/xdg-shell.c b/src/lib/desktop-shell/xdg-shell.c index b2a63e6..8ef5d05 100644 --- a/src/lib/desktop-shell/xdg-shell.c +++ b/src/lib/desktop-shell/xdg-shell.c @@ -376,11 +376,10 @@ pepper_bool_t init_xdg_shell(desktop_shell_t *shell) { struct wl_display *display = pepper_compositor_get_display(shell->compositor); - struct wl_global *global; - global = wl_global_create(display, &xdg_shell_interface, 1, shell, + shell->xdg_shell_global = wl_global_create(display, &xdg_shell_interface, 1, shell, bind_xdg_shell); - if (!global) + if (!shell->xdg_shell_global) return PEPPER_FALSE; return PEPPER_TRUE; @@ -389,5 +388,8 @@ init_xdg_shell(desktop_shell_t *shell) void fini_xdg_shell(desktop_shell_t *shell) { - /* TODO */ + if (shell->xdg_shell_global) { + wl_global_destroy(shell->xdg_shell_global); + shell->xdg_shell_global = NULL; + } } diff --git a/src/lib/devicemgr/pepper-devicemgr.c b/src/lib/devicemgr/pepper-devicemgr.c index 5d24ee7..70cc59c 100644 --- a/src/lib/devicemgr/pepper-devicemgr.c +++ b/src/lib/devicemgr/pepper-devicemgr.c @@ -245,6 +245,7 @@ _pepper_devicemgr_add_timer(pepper_devicemgr_t *pepper_devicemgr, wl_event_loop_ PEPPER_CHECK(event_loop, return PEPPER_FALSE, "Failed to get event_loop from display: %p\n", pepper_devicemgr->display); pepper_devicemgr->timer = wl_event_loop_add_timer(event_loop, func, pepper_devicemgr); + PEPPER_CHECK(pepper_devicemgr->timer, return PEPPER_FALSE, "Failed to timer\n"); wl_event_source_timer_update(pepper_devicemgr->timer, time); return PEPPER_TRUE; diff --git a/src/lib/pepper/utils.c b/src/lib/pepper/utils.c index 4d89f70..95fb07d 100644 --- a/src/lib/pepper/utils.c +++ b/src/lib/pepper/utils.c @@ -72,6 +72,7 @@ pepper_id_allocator_free(pepper_id_allocator_t *allocator, uint32_t id) if (allocator->free_id_count == allocator->free_id_size) { int i; uint32_t *ids = malloc((allocator->free_id_size + 64) * sizeof(uint32_t)); + PEPPER_CHECK(ids, return, "Failed to allocate memory for ids (free id size: %d).\n", allocator->free_id_size); for (i = 0; i < allocator->free_id_size; i++) { ids[i] = allocator->free_ids[allocator->free_id_head++]; diff --git a/src/lib/wayland/wayland-output.c b/src/lib/wayland/wayland-output.c index 0b9c691..dab4152 100644 --- a/src/lib/wayland/wayland-output.c +++ b/src/lib/wayland/wayland-output.c @@ -377,8 +377,19 @@ pepper_wayland_output_create(pepper_wayland_t *conn, int32_t w, int32_t h, /* Create wayland resources. */ output->surface = wl_compositor_create_surface(conn->compositor); + if (!output->surface) { + free(output); + return NULL; + } + output->shell_surface = wl_shell_get_shell_surface(conn->shell, output->surface); + if (!output->shell_surface) { + wl_surface_destroy(output->surface); + free(output); + return NULL; + } + wl_shell_surface_add_listener(output->shell_surface, &shell_surface_listener, output); wl_shell_surface_set_toplevel(output->shell_surface); -- 2.34.1