diff options
author | wm4 <wm4@nowhere> | 2014-12-14 22:00:21 +0100 |
---|---|---|
committer | Alessandro Ghedini <alessandro@ghedini.me> | 2014-12-17 20:11:41 +0100 |
commit | 015218f8c8aa9933928732b680e456ecc04f4800 (patch) | |
tree | f04f64f14974d34e7d67650c31331ee80b6b7d72 | |
parent | 00d1d6d807d52ef93c300df4e76d834143ac5962 (diff) | |
download | mpv-015218f8c8aa9933928732b680e456ecc04f4800.tar.bz2 mpv-015218f8c8aa9933928732b680e456ecc04f4800.tar.xz |
vo_x11: check allocation errors
Avoids a crash if allocation fails.
-rw-r--r-- | video/out/vo_x11.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/video/out/vo_x11.c b/video/out/vo_x11.c index 38a60c1be8..6eda4df131 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 @@ -212,6 +212,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 @@ -220,6 +224,7 @@ shmemerror: #if HAVE_SHM && HAVE_XEXT } #endif + return true; } static void freeMyXImage(struct priv *p, int foo) @@ -342,8 +347,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) { |