From 497bde6727260e7719c680dc483b10c0751a3fcd Mon Sep 17 00:00:00 2001 From: Julien Isorce Date: Thu, 5 Nov 2015 08:24:45 +0000 Subject: st/va: fix memory leak on error in vlVaCreateSurfaces2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found by coverity: CID #1337953 Signed-off-by: Julien Isorce Reviewed-by: Christian König Reviewed-by: Emil Velikov --- src/gallium/state_trackers/va/surface.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gallium/state_trackers/va/surface.c b/src/gallium/state_trackers/va/surface.c index 59815aa4c5..3db21c3de3 100644 --- a/src/gallium/state_trackers/va/surface.c +++ b/src/gallium/state_trackers/va/surface.c @@ -479,8 +479,10 @@ suface_from_external_memory(VADriverContextP ctx, vlVaSurface *surface, util_dynarray_init(&surface->subpics); surfaces[index] = handle_table_add(drv->htab, surface); - if (!surfaces[index]) + if (!surfaces[index]) { + surface->buffer->destroy(surface->buffer); return VA_STATUS_ERROR_ALLOCATION_FAILED; + } return VA_STATUS_SUCCESS; } @@ -612,15 +614,19 @@ vlVaCreateSurfaces2(VADriverContextP ctx, unsigned int format, switch (memory_type) { case VA_SURFACE_ATTRIB_MEM_TYPE_VA: surf->buffer = drv->pipe->create_video_buffer(drv->pipe, &templat); - if (!surf->buffer) + if (!surf->buffer) { + FREE(surf); goto no_res; + } util_dynarray_init(&surf->subpics); surfaces[i] = handle_table_add(drv->htab, surf); break; case VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: vaStatus = suface_from_external_memory(ctx, surf, memory_attibute, i, surfaces, &templat); - if (vaStatus != VA_STATUS_SUCCESS) + if (vaStatus != VA_STATUS_SUCCESS) { + FREE(surf); goto no_res; + } break; default: assert(0); -- cgit v1.2.3