From f2a24ccfa5ad1c09a7a75316a4589b5676d3945c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Jan 2017 06:57:48 +0100 Subject: [PATCH] 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. --- video/vaapi.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/video/vaapi.c b/video/vaapi.c index 604fffa738..1af1251b76 100644 --- a/video/vaapi.c +++ b/video/vaapi.c @@ -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; }