mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
proc: parse state and ppid from /proc/pid/status (v2)
v2: don't leak FILE CID 73423 (#1 of 1): Resource leak (RESOURCE_LEAK) 15. leaked_storage: Variable f going out of scope leaks the storage it points to. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
2cb6f2b68b
commit
05943959a5
17
proc_parse.c
17
proc_parse.c
@@ -745,7 +745,20 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (done < 6 && fgets(str, sizeof(str), f)) {
|
||||
while (done < 8 && fgets(str, sizeof(str), f)) {
|
||||
if (!strncmp(str, "State:", 6)) {
|
||||
cr->state = str[7];
|
||||
done++;
|
||||
}
|
||||
|
||||
if (!strncmp(str, "PPid:", 5)) {
|
||||
if (sscanf(str, "PPid:\t%d", &cr->ppid) != 1) {
|
||||
pr_err("Unable to parse: %s", str);
|
||||
goto err_parse;
|
||||
}
|
||||
done++;
|
||||
}
|
||||
|
||||
if (!strncmp(str, "Uid:", 4)) {
|
||||
if (ids_parse(str + 5, cr->uids))
|
||||
goto err_parse;
|
||||
@@ -789,7 +802,7 @@ int parse_pid_status(pid_t pid, struct proc_status_creds *cr)
|
||||
}
|
||||
}
|
||||
|
||||
if (done != 6) {
|
||||
if (done != 8) {
|
||||
err_parse:
|
||||
pr_err("Error parsing proc status file\n");
|
||||
fclose(f);
|
||||
|
Reference in New Issue
Block a user