Skip to content

Commit

Permalink
fix memory and file handle leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
luochunsheng authored and andikleen committed Aug 25, 2022
1 parent fb744b2 commit 59a9237
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ static int shm_pagesize;
static long huge_page_size(void)
{
size_t len = 0;
long huge_size = 0;
char *line = NULL;
FILE *f = fopen("/proc/meminfo", "r");
if (f != NULL) {
while (getdelim(&line, &len, '\n', f) > 0) {
int ps;
if (sscanf(line, "Hugepagesize: %d kB", &ps) == 1)
return ps * 1024;
if (sscanf(line, "Hugepagesize: %d kB", &ps) == 1) {
huge_size = ps * 1024;
break;
}
}
free(line);
fclose(f);
}
return getpagesize();
return huge_size ? huge_size : getpagesize();
}

static void check_region(char *opt)
Expand Down

0 comments on commit 59a9237

Please sign in to comment.