From: Eric Engestrom Date: Sun, 2 Feb 2020 17:04:29 +0000 (+0000) Subject: freedreno/perfcntrs: fix fd leak X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cae609326678bd00702261f756ce0c16efd530d4;p=mesa.git freedreno/perfcntrs: fix fd leak CoverityID: 1110568, 1458071 Fixes: 5a13507164a26fc796f0 ("freedreno/perfcntrs: add fdperf") Signed-off-by: Eric Engestrom Tested-by: Marge Bot Part-of: --- diff --git a/src/freedreno/perfcntrs/fdperf.c b/src/freedreno/perfcntrs/fdperf.c index 5b4488209c5..3c3b9912b3f 100644 --- a/src/freedreno/perfcntrs/fdperf.c +++ b/src/freedreno/perfcntrs/fdperf.c @@ -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"); + } } /*