asahi: Fix memory leak on error path.
authorVinson Lee <vlee@freedesktop.org>
Sun, 20 Nov 2022 22:08:50 +0000 (14:08 -0800)
committerMarge Bot <emma+marge@anholt.net>
Mon, 21 Nov 2022 04:38:55 +0000 (04:38 +0000)
Fix defect reported by Coverity Scan.

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

Fixes: 7522f4f7147 ("asahi: Make resource creation code modifier-aware")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19889>

src/gallium/drivers/asahi/agx_pipe.c

index 45e99eb..8e9a04b 100644 (file)
@@ -392,8 +392,10 @@ agx_resource_create_with_modifiers(struct pipe_screen *screen,
       nresource->modifier = agx_select_modifier_from_list(nresource, modifiers, count);
 
       /* There may not be a matching modifier, bail if so */
-      if (nresource->modifier == DRM_FORMAT_MOD_INVALID)
+      if (nresource->modifier == DRM_FORMAT_MOD_INVALID) {
+         free(nresource);
          return NULL;
+      }
    } else {
       nresource->modifier = agx_select_best_modifier(nresource);