mirror of https://github.com/xzeldon/htop.git
Fix memory leak on cgroup read failure
This commit is contained in:
parent
2c933f210b
commit
eb260af6bf
|
@ -251,7 +251,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
|
||||||
case VXID: xSnprintf(buffer, n, "%5u ", lp->vxid); break;
|
case VXID: xSnprintf(buffer, n, "%5u ", lp->vxid); break;
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_CGROUP
|
#ifdef HAVE_CGROUP
|
||||||
case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup); break;
|
case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup ? lp->cgroup : ""); break;
|
||||||
#endif
|
#endif
|
||||||
case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break;
|
case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break;
|
||||||
case IO_PRIORITY: {
|
case IO_PRIORITY: {
|
||||||
|
|
|
@ -509,7 +509,10 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d
|
||||||
xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name);
|
xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name);
|
||||||
FILE* file = fopen(filename, "r");
|
FILE* file = fopen(filename, "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
process->cgroup = xStrdup("");
|
if (process->cgroup) {
|
||||||
|
free(process->cgroup);
|
||||||
|
process->cgroup = NULL;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
char output[PROC_LINE_LENGTH + 1];
|
char output[PROC_LINE_LENGTH + 1];
|
||||||
|
|
Loading…
Reference in New Issue