scaler: Fix missing free for allocated resources 39/283039/1
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 13 Oct 2022 07:56:55 +0000 (16:56 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 17 Oct 2022 05:35:12 +0000 (14:35 +0900)
Change-Id: I5651bacd1b3927f123957575ec6d777a9fd5ab4a

src/scaler/scaler.c

index 9cd3b42..1a90207 100644 (file)
@@ -185,18 +185,14 @@ scaler_handle_get_viewport(struct wl_client *client,
     }
 
     viewport = calloc(1, sizeof *viewport);
-    if (!viewport) {
-        wl_resource_post_no_memory(resource);
-        return;
-    }
+    if (!viewport)
+        goto err_alloc;
 
     viewport->resource = wl_resource_create(client, &wl_viewport_interface,
             wl_resource_get_version(resource), id);
-    if (!viewport->resource) {
-        wl_resource_post_no_memory(resource);
-        free(viewport);
-        return;
-    }
+    if (!viewport->resource)
+        goto err_resource;
+
     wl_resource_set_implementation(viewport->resource, &viewport_iface,
             viewport, viewport_handle_resource_destroy);
 
@@ -207,6 +203,13 @@ scaler_handle_get_viewport(struct wl_client *client,
 
     viewport->surface_commit.notify = viewport_handle_surface_commit;
     ds_surface_add_commit_listener(surface, &viewport->surface_commit);
+
+    return;
+err_resource:
+    wl_resource_post_no_memory(resource);
+    free(viewport);
+err_alloc:
+    ds_surface_viewport_release(surface_viewport);
 }
 
 static const struct wl_scaler_interface scaler_iface = {