diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2015-02-20 14:52:10 -0200 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2015-02-20 14:52:10 -0200 |
commit | 6f868b00c02ef241216e7b95e0a09c38760c2f16 (patch) | |
tree | 905037b792a89fd8a2f6781e2656edf73a0fa590 /linux | |
parent | f97d1bc54af13e7c801bf6d83e95661f25695719 (diff) |
Fix allocation of processes. Closes #166.
Diffstat (limited to 'linux')
-rw-r--r-- | linux/LinuxProcess.c | 16 | ||||
-rw-r--r-- | linux/LinuxProcess.h | 6 | ||||
-rw-r--r-- | linux/LinuxProcessList.c | 5 | ||||
-rw-r--r-- | linux/Platform.c | 1 | ||||
-rw-r--r-- | linux/Platform.h | 1 |
5 files changed, 27 insertions, 2 deletions
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 8a67f608..401a4836 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -10,6 +10,7 @@ in the source distribution for its full text. #include "LinuxProcess.h" #include "CRT.h" +#include <stdlib.h> #include <unistd.h> #include <sys/syscall.h> @@ -22,8 +23,23 @@ typedef struct LinuxProcess_ { IOPriority ioPriority; } LinuxProcess; +#define Process_delete LinuxProcess_delete + }*/ +LinuxProcess* LinuxProcess_new(Settings* settings) { + LinuxProcess* this = calloc(sizeof(LinuxProcess), 1); + Process_init(&this->super, settings); + return this; +} + +void LinuxProcess_delete(Object* cast) { + LinuxProcess* this = (LinuxProcess*) this; + Object_setClass(this, Class(Process)); + Process_done((Process*)cast); + free(this); +} + /* [1] Note that before kernel 2.6.26 a process that has not asked for an io priority formally uses "none" as scheduling class, but the diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index beafff64..41a82c26 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -17,6 +17,12 @@ typedef struct LinuxProcess_ { IOPriority ioPriority; } LinuxProcess; +#define Process_delete LinuxProcess_delete + + +LinuxProcess* LinuxProcess_new(Settings* settings); + +void LinuxProcess_delete(Object* cast); /* [1] Note that before kernel 2.6.26 a process that has not asked for diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index aed530dd..2bb207ee 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -375,6 +375,7 @@ static void LinuxProcessList_readCGroupFile(Process* process, const char* dirnam int nFields; char** fields = String_split(trimmed, ':', &nFields); free(trimmed); + free(process->cgroup); if (nFields >= 3) { process->cgroup = strndup(fields[2] + 1, 10); } else { @@ -521,7 +522,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char* process = existingProcess; assert(process->pid == pid); } else { - process = Process_new(settings); + process = (Process*) LinuxProcess_new(settings); assert(process->comm == NULL); process->pid = pid; process->tgid = parent ? parent->pid : pid; @@ -625,7 +626,7 @@ static bool LinuxProcessList_processEntries(LinuxProcessList* this, const char* if (existingProcess) ProcessList_remove((ProcessList*)this, process); else - Process_delete((Object*)process); + LinuxProcess_delete((Object*)process); } } closedir(dir); diff --git a/linux/Platform.c b/linux/Platform.c index 0a763362..8d3e2976 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -29,6 +29,7 @@ in the source distribution for its full text. #include "Action.h" #include "MainPanel.h" #include "BatteryMeter.h" +#include "LinuxProcess.h" }*/ static Htop_Reaction Platform_actionSetIOPriority(State* st) { diff --git a/linux/Platform.h b/linux/Platform.h index c4a5cd24..de7ca919 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -12,6 +12,7 @@ in the source distribution for its full text. #include "Action.h" #include "MainPanel.h" #include "BatteryMeter.h" +#include "LinuxProcess.h" void Platform_setBindings(Htop_Action* keys); |