From owner-svn-src-head@FreeBSD.ORG Sat Jun 30 16:20:02 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A6F181065673; Sat, 30 Jun 2012 16:20:02 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8C9ED8FC0C; Sat, 30 Jun 2012 16:20:02 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5UGK2s9028853; Sat, 30 Jun 2012 16:20:02 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5UGK2CH028852; Sat, 30 Jun 2012 16:20:02 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201206301620.q5UGK2CH028852@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 30 Jun 2012 16:20:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237844 - head/usr.bin/killall X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jun 2012 16:20:02 -0000 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);