steamcompmgr: Make get_appid_from_pid more robust
Was some undefined value ptrs going on here, and not checking if the PID stat opened successfully.
This commit is contained in:
parent
f4f0239b31
commit
48d726c72b
1 changed files with 8 additions and 1 deletions
|
@ -3382,12 +3382,16 @@ get_appid_from_pid( pid_t pid )
|
||||||
{
|
{
|
||||||
snprintf( filename, sizeof( filename ), "/proc/%i/stat", next_pid );
|
snprintf( filename, sizeof( filename ), "/proc/%i/stat", next_pid );
|
||||||
std::ifstream proc_stat_file( filename );
|
std::ifstream proc_stat_file( filename );
|
||||||
|
|
||||||
|
if (!proc_stat_file.is_open() || proc_stat_file.bad())
|
||||||
|
break;
|
||||||
|
|
||||||
std::string proc_stat;
|
std::string proc_stat;
|
||||||
|
|
||||||
std::getline( proc_stat_file, proc_stat );
|
std::getline( proc_stat_file, proc_stat );
|
||||||
|
|
||||||
char *procName = nullptr;
|
char *procName = nullptr;
|
||||||
char *lastParens;
|
char *lastParens = nullptr;
|
||||||
|
|
||||||
for ( uint32_t i = 0; i < proc_stat.length(); i++ )
|
for ( uint32_t i = 0; i < proc_stat.length(); i++ )
|
||||||
{
|
{
|
||||||
|
@ -3402,6 +3406,9 @@ get_appid_from_pid( pid_t pid )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!lastParens)
|
||||||
|
break;
|
||||||
|
|
||||||
*lastParens = '\0';
|
*lastParens = '\0';
|
||||||
char state;
|
char state;
|
||||||
int parent_pid = -1;
|
int parent_pid = -1;
|
||||||
|
|
Loading…
Reference in a new issue