diff options
author | wm4 <wm4@nowhere> | 2017-01-08 06:57:48 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-01-08 07:32:44 +0100 |
commit | f2a24ccfa5ad1c09a7a75316a4589b5676d3945c (patch) | |
tree | 3574fb7c2160f9e3c24db60b5e2b35c9ec694d9d /video/vaapi.c | |
parent | 68d737bd92c7a8c9a12033604e171581b14fe232 (diff) | |
download | mpv-f2a24ccfa5ad1c09a7a75316a4589b5676d3945c.tar.bz2 mpv-f2a24ccfa5ad1c09a7a75316a4589b5676d3945c.tar.xz |
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.
Diffstat (limited to 'video/vaapi.c')
-rw-r--r-- | video/vaapi.c | 30 |
1 files 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; } |