summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-07 00:59:25 +0100
committerwm4 <wm4@nowhere>2014-01-07 01:07:50 +0100
commit326d887a41dd2eefdc8496e218ada1a0d0379a70 (patch)
treed15e529dfa68e0bd446246c73bbf438df340b609
parentcf6f1106eac31499f645720b5e1598a995de1f71 (diff)
downloadmpv-326d887a41dd2eefdc8496e218ada1a0d0379a70.tar.bz2
mpv-326d887a41dd2eefdc8496e218ada1a0d0379a70.tar.xz
wayland: fix some memory leaks on initialization failure
This commonly happens when initializing vo_opengl on a X11-only system. Unfortunately, most wl_*_destroy() functions appear not to accept NULL pointers, making partial deinitialization a pain: you have to add your own NULL checks everywhere to avoid crashes. xkb.context is uninitialized separately, because you can initialize it just fine, even if the rest of input initialization fails.
-rw-r--r--video/out/wayland_common.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 0948fb0ca5..00c136bdb2 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -767,9 +767,12 @@ static void destroy_display (struct vo_wayland_state *wl)
if (wl->display.compositor)
wl_compositor_destroy(wl->display.compositor);
- wl_registry_destroy(wl->display.registry);
- wl_display_flush(wl->display.display);
- wl_display_disconnect(wl->display.display);
+ if (wl->display.registry)
+ wl_registry_destroy(wl->display.registry);
+ if (wl->display.display) {
+ wl_display_flush(wl->display.display);
+ wl_display_disconnect(wl->display.display);
+ }
}
static bool create_window (struct vo_wayland_state *wl)
@@ -794,8 +797,10 @@ static bool create_window (struct vo_wayland_state *wl)
static void destroy_window (struct vo_wayland_state *wl)
{
- wl_shell_surface_destroy(wl->window.shell_surface);
- wl_surface_destroy(wl->window.surface);
+ if (wl->window.shell_surface)
+ wl_shell_surface_destroy(wl->window.shell_surface);
+ if (wl->window.surface)
+ wl_surface_destroy(wl->window.surface);
}
static bool create_cursor (struct vo_wayland_state *wl)
@@ -846,8 +851,9 @@ static void destroy_input (struct vo_wayland_state *wl)
wl_keyboard_destroy(wl->input.keyboard);
xkb_map_unref(wl->input.xkb.keymap);
xkb_state_unref(wl->input.xkb.state);
- xkb_context_unref(wl->input.xkb.context);
}
+ if (wl->input.xkb.context)
+ xkb_context_unref(wl->input.xkb.context);
if (wl->input.pointer)
wl_pointer_destroy(wl->input.pointer);
@@ -876,6 +882,7 @@ int vo_wayland_init (struct vo *vo)
|| !create_window(wl)
|| !create_cursor(wl))
{
+ vo_wayland_uninit(vo);
return false;
}