mirror of https://github.com/xzeldon/htop.git
Fix NULL pointer dereference on kstat_lookup failure
This commit is contained in:
parent
d2c64c16e6
commit
51be2d5415
|
@ -151,24 +151,22 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int Platform_getMaxPid() {
|
int Platform_getMaxPid() {
|
||||||
kstat_ctl_t* kc = NULL;
|
|
||||||
kstat_t* kshandle = NULL;
|
|
||||||
kvar_t* ksvar = NULL;
|
|
||||||
int vproc = 32778; // Reasonable Solaris default
|
int vproc = 32778; // Reasonable Solaris default
|
||||||
kc = kstat_open();
|
|
||||||
|
kstat_ctl_t* kc = kstat_open();
|
||||||
if (kc != NULL) {
|
if (kc != NULL) {
|
||||||
kshandle = kstat_lookup(kc, "unix", 0, "var");
|
kstat_t* kshandle = kstat_lookup(kc, "unix", 0, "var");
|
||||||
}
|
|
||||||
if (kshandle != NULL) {
|
if (kshandle != NULL) {
|
||||||
kstat_read(kc, kshandle, NULL);
|
kstat_read(kc, kshandle, NULL);
|
||||||
}
|
|
||||||
ksvar = kshandle->ks_data;
|
kvar_t* ksvar = kshandle->ks_data;
|
||||||
if (ksvar->v_proc > 0 ) {
|
if (ksvar && ksvar->v_proc > 0) {
|
||||||
vproc = ksvar->v_proc;
|
vproc = ksvar->v_proc;
|
||||||
}
|
}
|
||||||
if (kc != NULL) {
|
}
|
||||||
kstat_close(kc);
|
kstat_close(kc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return vproc;
|
return vproc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue