Skip to content

Commit 9dedec5

Browse files
committed
sysinfos: fix some file leaks
1 parent c120eca commit 9dedec5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

api.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,12 @@ static const char* os_name()
321321
return "windows";
322322
#else
323323
FILE *fd = fopen("/proc/version", "r");
324-
if (!fd || !fscanf(fd, "Linux version %48s", &os_version[6]))
324+
if (!fd)
325325
return "linux";
326+
if (!fscanf(fd, "Linux version %48s", &os_version[6])) {
327+
fclose(fd);
328+
return "linux";
329+
}
326330
fclose(fd);
327331
os_version[48] = '\0';
328332
return (const char*) os_version;

sysinfos.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ static uint32_t linux_cpufreq(int core)
5050
return freq;
5151

5252
if (!fscanf(fd, "%d", &freq))
53-
return freq;
53+
;
5454

55+
fclose(fd);
5556
return freq;
5657
}
5758

0 commit comments

Comments
 (0)