1
mirror of https://github.com/mpv-player/mpv synced 2024-11-03 03:19:24 +01:00

vaapi: rearrange va_initialize() internals and fix double-free on error

Just some minor refactoring within va_initialize() as preparation for
the next commit.

Also, do not call vaTerminate(display) on failures. All callers already
do this, so this would have led to a double-free.
This commit is contained in:
wm4 2017-01-08 06:57:48 +01:00
parent 68d737bd92
commit f2a24ccfa5

View File

@ -111,20 +111,9 @@ static void va_get_formats(struct mp_vaapi_ctx *ctx)
struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
bool probing)
{
struct mp_vaapi_ctx *res = NULL;
struct mp_log *log = mp_log_new(NULL, plog, "/vaapi");
int major_version, minor_version;
int status = vaInitialize(display, &major_version, &minor_version);
if (status != VA_STATUS_SUCCESS && probing)
goto error;
if (!check_va_status(log, status, "vaInitialize()"))
goto error;
mp_verbose(log, "VA API version %d.%d\n", major_version, minor_version);
res = talloc_ptrtype(NULL, res);
struct mp_vaapi_ctx *res = talloc_ptrtype(NULL, res);
*res = (struct mp_vaapi_ctx) {
.log = talloc_steal(res, log),
.log = mp_log_new(res, plog, "/vaapi"),
.display = display,
.hwctx = {
.type = HWDEC_VAAPI,
@ -134,16 +123,23 @@ struct mp_vaapi_ctx *va_initialize(VADisplay *display, struct mp_log *plog,
};
mpthread_mutex_init_recursive(&res->lock);
int major_version, minor_version;
int status = vaInitialize(display, &major_version, &minor_version);
if (status != VA_STATUS_SUCCESS && probing)
goto error;
if (!check_va_status(res->log, status, "vaInitialize()"))
goto error;
MP_VERBOSE(res, "VA API version %d.%d\n", major_version, minor_version);
va_get_formats(res);
if (!res->image_formats)
goto error;
return res;
error:
if (res && res->display)
vaTerminate(res->display);
talloc_free(log);
talloc_free(res);
res->display = NULL; // do not vaTerminate this
va_destroy(res);
return NULL;
}