st/va: fix memory leak on error in vlVaCreateSurfaces2

Found by coverity: CID #1337953

Signed-off-by: Julien Isorce <j.isorce@samsung.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
This commit is contained in:
Julien Isorce
2015-11-05 08:24:45 +00:00
committed by Emil Velikov
parent e0b896c86c
commit 497bde6727
+9 -3
View File
@@ -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);