radv/winsys: Fix mem leak at failed do_winsys_init() call site
authorEdward O'Callaghan <funfunctor@folklore1984.net>
Tue, 11 Oct 2016 11:43:07 +0000 (22:43 +1100)
committerDave Airlie <airlied@redhat.com>
Tue, 11 Oct 2016 22:46:10 +0000 (08:46 +1000)
Probably unlikely however ensure we don't leak a heap allocation
on the fail path.

V.2:
 also fix missing 'amdgpu_device_deinitialize()' calls (Emil Velikov).

Signed-off-by: Edward O'Callaghan <funfunctor@folklore1984.net>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c

index 0ce44acd39d7ebf07c749a22f9f054fe3962fee9..04561007258a47cfbd4ef1f91223220998d3701a 100644 (file)
@@ -337,13 +337,13 @@ radv_amdgpu_winsys_create(int fd)
 
        ws = calloc(1, sizeof(struct radv_amdgpu_winsys));
        if (!ws)
-               return NULL;
+               goto fail;
 
        ws->dev = dev;
        ws->info.drm_major = drm_major;
        ws->info.drm_minor = drm_minor;
        if (!do_winsys_init(ws, fd))
-               goto fail;
+               goto winsys_fail;
 
        ws->debug_all_bos = getenv("RADV_DEBUG_ALL_BOS") ? true : false;
        LIST_INITHEAD(&ws->global_bo_list);
@@ -355,6 +355,10 @@ radv_amdgpu_winsys_create(int fd)
        radv_amdgpu_surface_init_functions(ws);
 
        return &ws->base;
+
+winsys_fail:
+       free(ws);
 fail:
+       amdgpu_device_deinitialize(dev);
        return NULL;
 }