summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-01-08 06:57:48 +0100
committerwm4 <wm4@nowhere>2017-01-08 07:32:44 +0100
commitf2a24ccfa5ad1c09a7a75316a4589b5676d3945c (patch)
tree3574fb7c2160f9e3c24db60b5e2b35c9ec694d9d /video
parent68d737bd92c7a8c9a12033604e171581b14fe232 (diff)
downloadmpv-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')
-rw-r--r--video/vaapi.c30
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;
}