v4l2-ctl: Do not leak framebuffer handle in error paths
authorGregor Jasny <gjasny@googlemail.com>
Wed, 23 Apr 2014 07:28:46 +0000 (09:28 +0200)
committerGregor Jasny <gjasny@googlemail.com>
Wed, 23 Apr 2014 07:54:51 +0000 (09:54 +0200)
Detected by Coverity

Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-ctl/v4l2-ctl-overlay.cpp

index 5bc99a5..38bb346 100644 (file)
@@ -161,6 +161,7 @@ static void find_fb(int fd)
                        if (si.smem_start == (unsigned long)fbuf.base) {
                                printf("%s is the framebuffer associated with base address %p\n",
                                        dev_name, fbuf.base);
+                               close(fb_fd);
                                return;
                        }
                close(fb_fd);
@@ -211,10 +212,12 @@ static int fbuf_fill_from_fb(struct v4l2_framebuffer &fb, const char *fb_device)
        }
        if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &si)) {
                fprintf(stderr, "could not obtain fscreeninfo from %s\n", fb_device);
+               close(fb_fd);
                return -1;
        }
        if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &vi)) {
                fprintf(stderr, "could not obtain vscreeninfo from %s\n", fb_device);
+               close(fb_fd);
                return -1;
        }
        fb.base = (void *)si.smem_start;
@@ -224,6 +227,7 @@ static int fbuf_fill_from_fb(struct v4l2_framebuffer &fb, const char *fb_device)
        fb.fmt.bytesperline = si.line_length;
        if (fb.fmt.height * fb.fmt.bytesperline > fb.fmt.sizeimage) {
                fprintf(stderr, "height * bytesperline > sizeimage?!\n");
+               close(fb_fd);
                return -1;
        }
        fb.fmt.pixelformat = 0;