asahi: Fix memory leak on error path.
authorVinson Lee <vlee@freedesktop.org>
Sun, 20 Nov 2022 21:41:55 +0000 (13:41 -0800)
committerVinson Lee <vlee@freedesktop.org>
Sun, 20 Nov 2022 21:41:55 +0000 (13:41 -0800)
Fix defect reported by Coverity Scan.

Resource leak (RESOURCE_LEAK)
leaked_storage: Variable rsc going out of scope leaks the storage it points to.

Fixes: 01964625eb2 ("asahi: Implement agx_resource_from_handle")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19887>

src/gallium/drivers/asahi/agx_pipe.c

index 1e33729..45e99eb 100644 (file)
@@ -174,8 +174,10 @@ agx_resource_from_handle(struct pipe_screen *pscreen,
    /* We need strides to be aligned. ail asserts this, but we want to fail
     * gracefully so the app can handle the error.
     */
-   if (rsc->modifier == DRM_FORMAT_MOD_LINEAR && (whandle->stride % 16) != 0)
+   if (rsc->modifier == DRM_FORMAT_MOD_LINEAR && (whandle->stride % 16) != 0) {
+      FREE(rsc);
       return false;
+   }
 
    prsc = &rsc->base;