Skip to content

Commit

Permalink
sysinfos: fix some file leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Jun 22, 2017
1 parent c120eca commit 9dedec5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion sysinfos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ static uint32_t linux_cpufreq(int core)
return freq;

if (!fscanf(fd, "%d", &freq))
return freq;
;

fclose(fd);
return freq;
}

Expand Down

0 comments on commit 9dedec5

Please sign in to comment.