From 9dedec5ecdae104405f821decbf9e38824477c4e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 22 Jun 2017 07:38:40 +0200 Subject: [PATCH] sysinfos: fix some file leaks --- api.cpp | 6 +++++- sysinfos.cpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api.cpp b/api.cpp index 8353127..87d3095 100644 --- a/api.cpp +++ b/api.cpp @@ -321,8 +321,12 @@ static const char* os_name() return "windows"; #else FILE *fd = fopen("/proc/version", "r"); - if (!fd || !fscanf(fd, "Linux version %48s", &os_version[6])) + if (!fd) return "linux"; + if (!fscanf(fd, "Linux version %48s", &os_version[6])) { + fclose(fd); + return "linux"; + } fclose(fd); os_version[48] = '\0'; return (const char*) os_version; diff --git a/sysinfos.cpp b/sysinfos.cpp index 4515830..e5d9396 100644 --- a/sysinfos.cpp +++ b/sysinfos.cpp @@ -50,8 +50,9 @@ static uint32_t linux_cpufreq(int core) return freq; if (!fscanf(fd, "%d", &freq)) - return freq; + ; + fclose(fd); return freq; }