svn commit: r237844 - head/usr.bin/killall
Konstantin Belousov
kib at FreeBSD.org
Sat Jun 30 16:20:02 UTC 2012
Author: kib
Date: Sat Jun 30 16:20:01 2012
New Revision: 237844
URL: http://svn.freebsd.org/changeset/base/237844
Log:
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
Modified:
head/usr.bin/killall/killall.c
Modified: head/usr.bin/killall/killall.c
==============================================================================
--- head/usr.bin/killall/killall.c Sat Jun 30 15:55:40 2012 (r237843)
+++ head/usr.bin/killall/killall.c Sat Jun 30 16:20:01 2012 (r237844)
@@ -90,7 +90,7 @@ nosig(char *name)
int
main(int ac, char **av)
{
- struct kinfo_proc *procs = NULL, *newprocs;
+ struct kinfo_proc *procs, *newprocs;
struct stat sb;
struct passwd *pw;
regex_t rgx;
@@ -292,14 +292,14 @@ main(int ac, char **av)
miblen = 4;
}
+ procs = NULL;
st = sysctl(mib, miblen, NULL, &size, NULL, 0);
do {
size += size / 10;
newprocs = realloc(procs, size);
- if (newprocs == 0) {
- if (procs)
- free(procs);
- errx(1, "could not reallocate memory");
+ if (newprocs == NULL) {
+ free(procs);
+ err(1, "could not reallocate memory");
}
procs = newprocs;
st = sysctl(mib, miblen, procs, &size, NULL, 0);
More information about the svn-src-head
mailing list