summaryrefslogtreecommitdiffstats
path: root/openbsd
diff options
context:
space:
mode:
authorMichael McConville <mmcco@mykolab.com>2016-01-03 16:56:33 -0500
committerMichael McConville <mmcco@mykolab.com>2016-01-03 16:56:33 -0500
commit198592a0f1d688f75820111be64ba9e2da4ac679 (patch)
tree897c6643fb772e69ccc1515d4ca78d01d5b6269e /openbsd
parentbe9edc5d4302fc83281e6323bc1df72796c1b49c (diff)
Plug mem leak, improve CPU enumeration logic
I think this leak may still exist in the FreeBSD port.
Diffstat (limited to 'openbsd')
-rw-r--r--openbsd/OpenBSDProcessList.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c
index 25f63349..9757ef91 100644
--- a/openbsd/OpenBSDProcessList.c
+++ b/openbsd/OpenBSDProcessList.c
@@ -48,19 +48,21 @@ static long fscale;
ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
int mib[] = { CTL_HW, HW_NCPU };
int fmib[] = { CTL_KERN, KERN_FSCALE };
- int i;
+ int i, e;
OpenBSDProcessList* fpl = calloc(1, sizeof(OpenBSDProcessList));
ProcessList* pl = (ProcessList*) fpl;
size_t size = sizeof(pl->cpuCount);
ProcessList_init(pl, Class(OpenBSDProcess), usersTable, pidWhiteList, userId);
- pl->cpuCount = 1; // default to 1 on sysctl() error
- (void)sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0);
+ e = sysctl(mib, 2, &pl->cpuCount, &size, NULL, 0);
+ if (e == -1 || pl->cpuCount < 1) {
+ pl->cpuCount = 1;
+ }
fpl->cpus = realloc(fpl->cpus, pl->cpuCount * sizeof(CPUData));
size = sizeof(fscale);
if (sysctl(fmib, 2, &fscale, &size, NULL, 0) < 0)
- err(1, "fscale sysctl call failed");
+ err(1, "fscale sysctl call failed");
for (i = 0; i < pl->cpuCount; i++) {
fpl->cpus[i].totalTime = 1;
@@ -80,6 +82,8 @@ void ProcessList_delete(ProcessList* this) {
const OpenBSDProcessList* fpl = (OpenBSDProcessList*) this;
if (fpl->kd) kvm_close(fpl->kd);
+ free(fpl->cpus);
+
ProcessList_done(this);
free(this);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy