fix svace issues 46/250146/3 accepted/tizen/unified/20201223.125047 submit/tizen/20201222.032115
authorjeon <jhyuni.kang@samsung.com>
Mon, 21 Dec 2020 07:30:25 +0000 (16:30 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 22 Dec 2020 03:11:33 +0000 (12:11 +0900)
  - add null check
  - free allocated memory

Change-Id: Ic609fce530c41e877311d83764c178cfd73bfeb4

src/lib/desktop-shell/desktop-shell-internal.h
src/lib/desktop-shell/wl-shell.c
src/lib/desktop-shell/xdg-shell.c
src/lib/devicemgr/pepper-devicemgr.c
src/lib/pepper/utils.c
src/lib/wayland/wayland-output.c

index 8c5bbc2..31ce1a7 100644 (file)
@@ -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;
 
index c2cbe49..6555ea4 100644 (file)
@@ -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;
+       }
 }
index b2a63e6..8ef5d05 100644 (file)
@@ -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;
+       }
 }
index 5d24ee7..70cc59c 100644 (file)
@@ -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;
index 4d89f70..95fb07d 100644 (file)
@@ -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++];
index 0b9c691..dab4152 100644 (file)
@@ -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);