Prevent file descriptor from unclosed

This commit is contained in:
topjohnwu
2018-11-23 21:15:44 -05:00
parent 762b678d24
commit ec4723096f
3 changed files with 4 additions and 3 deletions

View File

@@ -51,11 +51,12 @@ static int parse_ppid(int pid) {
char path[32];
int ppid;
sprintf(path, "/proc/%d/stat", pid);
FILE *stat = fopen(path, "r");
FILE *stat = xfopen(path, "re");
if (stat == nullptr)
return -1;
/* PID COMM STATE PPID ..... */
fscanf(stat, "%*d %*s %*c %d", &ppid);
fclose(stat);
return ppid;
}