Initialize procs closer to the place were it is used.
Free can properly handle NULL pointer (but keep free() call on the premise that the code might be reused). Show errno when realloc failed. MFC after: 3 days
This commit is contained in:
parent
5f42fa1793
commit
40bcb503f1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=237844
@ -90,7 +90,7 @@ nosig(char *name)
|
|||||||
int
|
int
|
||||||
main(int ac, char **av)
|
main(int ac, char **av)
|
||||||
{
|
{
|
||||||
struct kinfo_proc *procs = NULL, *newprocs;
|
struct kinfo_proc *procs, *newprocs;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
regex_t rgx;
|
regex_t rgx;
|
||||||
@ -292,14 +292,14 @@ main(int ac, char **av)
|
|||||||
miblen = 4;
|
miblen = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
procs = NULL;
|
||||||
st = sysctl(mib, miblen, NULL, &size, NULL, 0);
|
st = sysctl(mib, miblen, NULL, &size, NULL, 0);
|
||||||
do {
|
do {
|
||||||
size += size / 10;
|
size += size / 10;
|
||||||
newprocs = realloc(procs, size);
|
newprocs = realloc(procs, size);
|
||||||
if (newprocs == 0) {
|
if (newprocs == NULL) {
|
||||||
if (procs)
|
free(procs);
|
||||||
free(procs);
|
err(1, "could not reallocate memory");
|
||||||
errx(1, "could not reallocate memory");
|
|
||||||
}
|
}
|
||||||
procs = newprocs;
|
procs = newprocs;
|
||||||
st = sysctl(mib, miblen, procs, &size, NULL, 0);
|
st = sysctl(mib, miblen, procs, &size, NULL, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user