Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jun 2012 16:20:02 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r237844 - head/usr.bin/killall
Message-ID:  <201206301620.q5UGK2CH028852@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206301620.q5UGK2CH028852>