avdevice/xcbgrab: Handle reply and error properly
authorKusanagi Kouichi <slash@ac.auone-net.jp>
Tue, 19 Nov 2019 13:59:30 +0000 (22:59 +0900)
committerMarton Balint <cus@passwd.hu>
Tue, 3 Dec 2019 20:13:00 +0000 (21:13 +0100)
Fix a NULL dereference and leaks.

Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: Marton Balint <cus@passwd.hu>
libavdevice/xcbgrab.c

index b7e6893..063fecf 100644 (file)
@@ -168,6 +168,7 @@ static int xcbgrab_frame(AVFormatContext *s, AVPacket *pkt)
                "sequence:%u resource_id:%u minor_code:%u major_code:%u.\n",
                e->response_type, e->error_code,
                e->sequence, e->resource_id, e->minor_code, e->major_code);
+        free(e);
         return AVERROR(EACCES);
     }
 
@@ -276,6 +277,7 @@ static int xcbgrab_frame_shm(AVFormatContext *s, AVPacket *pkt)
                e->response_type, e->error_code,
                e->sequence, e->resource_id, e->minor_code, e->major_code);
 
+        free(e);
         return AVERROR(EACCES);
     }
 
@@ -537,6 +539,8 @@ static int create_stream(AVFormatContext *s)
 
     gc  = xcb_get_geometry(c->conn, c->screen->root);
     geo = xcb_get_geometry_reply(c->conn, gc, NULL);
+    if (!geo)
+        return AVERROR_EXTERNAL;
 
     if (c->x + c->width > geo->width ||
         c->y + c->height > geo->height) {
@@ -546,6 +550,7 @@ static int create_stream(AVFormatContext *s)
                c->width, c->height,
                c->x, c->y,
                geo->width, geo->height);
+        free(geo);
         return AVERROR(EINVAL);
     }