freedreno/perfcntrs: fix fd leak
authorEric Engestrom <eric@engestrom.ch>
Sun, 2 Feb 2020 17:04:29 +0000 (17:04 +0000)
committerMarge Bot <eric+marge@anholt.net>
Tue, 4 Feb 2020 19:26:40 +0000 (19:26 +0000)
CoverityID: 11105681458071
Fixes: 5a13507164a26fc796f0 ("freedreno/perfcntrs: add fdperf")
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3671>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3671>

src/freedreno/perfcntrs/fdperf.c

index 5b4488209c5a7583e056cf65b2808ebe7995f46c..3c3b9912b3f80404b7d44a8e27069bd231fba2f8 100644 (file)
@@ -123,10 +123,12 @@ readfile(const char *path, int *sz)
                if (ret < 0) {
                        free(buf);
                        *sz = 0;
+                       close(fd);
                        return NULL;
                } else if (ret < CHUNKSIZE) {
                        n += ret;
                        *sz = n;
+                       close(fd);
                        return buf;
                } else {
                        n += CHUNKSIZE;
@@ -393,8 +395,10 @@ find_device(void)
                err(1, "could not open /dev/mem");
 
        dev.io = mmap(0, dev.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, dev.base);
-       if (!dev.io)
+       if (!dev.io) {
+               close(fd);
                err(1, "could not map device");
+       }
 }
 
 /*