From 399e2fec6ba70a22e8ab91a1ffb5b60c47778bd8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 14 Dec 2014 22:00:21 +0100 Subject: vo_x11: check allocation errors Avoids a crash if allocation fails. --- video/out/vo_x11.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c index 90e3eb52be..37e9607f0a 100644 --- a/video/out/vo_x11.c +++ b/video/out/vo_x11.c @@ -152,7 +152,7 @@ static int find_depth_from_visuals(struct vo *vo, Visual ** visual_return) return bestvisual_depth; } -static void getMyXImage(struct priv *p, int foo) +static bool getMyXImage(struct priv *p, int foo) { struct vo *vo = p->vo; #if HAVE_SHM && HAVE_XEXT @@ -210,6 +210,10 @@ shmemerror: p->myximage[foo] = XCreateImage(vo->x11->display, p->vinfo.visual, p->depth, ZPixmap, 0, NULL, p->image_width, p->image_height, 8, 0); + if (!p->myximage[foo]) { + MP_WARN(vo, "could not allocate image"); + return false; + } size_t sz = p->myximage[foo]->bytes_per_line * p->image_height + 32; p->ImageDataOrig[foo] = calloc(1, sz); p->myximage[foo]->data = p->ImageDataOrig[foo] + 16 @@ -218,6 +222,7 @@ shmemerror: #if HAVE_SHM && HAVE_XEXT } #endif + return true; } static void freeMyXImage(struct priv *p, int foo) @@ -340,8 +345,10 @@ static bool resize(struct vo *vo) p->image_height = p->dst_h; p->num_buffers = 2; - for (int i = 0; i < p->num_buffers; i++) - getMyXImage(p, i); + for (int i = 0; i < p->num_buffers; i++) { + if (!getMyXImage(p, i)) + return -1; + } const struct fmt2Xfmtentry_s *fmte = fmt2Xfmt; while (fmte->mpfmt) { -- cgit v1.2.3