Fix NULL pointer dereference on kstat_lookup failure

This commit is contained in:
Benny Baumann 2020-11-22 00:47:00 +01:00 committed by Christian Göttsche
parent d2c64c16e6
commit 51be2d5415
1 changed files with 12 additions and 14 deletions

View File

@ -151,24 +151,22 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
}
int Platform_getMaxPid() {
kstat_ctl_t* kc = NULL;
kstat_t* kshandle = NULL;
kvar_t* ksvar = NULL;
int vproc = 32778; // Reasonable Solaris default
kc = kstat_open();
if (kc != NULL) {
kshandle = kstat_lookup(kc, "unix", 0, "var");
}
if (kshandle != NULL) {
kstat_read(kc, kshandle, NULL);
}
ksvar = kshandle->ks_data;
if (ksvar->v_proc > 0 ) {
vproc = ksvar->v_proc;
}
kstat_ctl_t* kc = kstat_open();
if (kc != NULL) {
kstat_t* kshandle = kstat_lookup(kc, "unix", 0, "var");
if (kshandle != NULL) {
kstat_read(kc, kshandle, NULL);
kvar_t* ksvar = kshandle->ks_data;
if (ksvar && ksvar->v_proc > 0) {
vproc = ksvar->v_proc;
}
}
kstat_close(kc);
}
return vproc;
}