Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/systat systat(1): convert free(x); x = malloc(x * y)...



details:   https://anonhg.NetBSD.org/src/rev/bf028fc5eeed
branches:  trunk
changeset: 1025499:bf028fc5eeed
user:      nia <nia%NetBSD.org@localhost>
date:      Tue Nov 09 09:18:02 2021 +0000

description:
systat(1): convert free(x); x = malloc(x * y) to reallocarr.

free on NULL is a guaranteed non-op.

diffstat:

 usr.bin/systat/pigs.c |  11 ++++-------
 usr.bin/systat/swap.c |  10 ++++------
 2 files changed, 8 insertions(+), 13 deletions(-)

diffs (66 lines):

diff -r ccea04594f21 -r bf028fc5eeed usr.bin/systat/pigs.c
--- a/usr.bin/systat/pigs.c     Mon Nov 08 23:57:23 2021 +0000
+++ b/usr.bin/systat/pigs.c     Tue Nov 09 09:18:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pigs.c,v 1.33 2012/11/23 03:46:35 christos Exp $       */
+/*     $NetBSD: pigs.c,v 1.34 2021/11/09 09:18:02 nia Exp $    */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pigs.c     8.2 (Berkeley) 9/23/93";
 #endif
-__RCSID("$NetBSD: pigs.c,v 1.33 2012/11/23 03:46:35 christos Exp $");
+__RCSID("$NetBSD: pigs.c,v 1.34 2021/11/09 09:18:02 nia Exp $");
 #endif /* not lint */
 
 /*
@@ -179,14 +179,11 @@
        if ((kpp = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(*kpp),
                                &nproc)) == NULL) {
                error("%s", kvm_geterr(kd));
-               if (pt)
-                       free(pt);
+               free(pt);
                return;
        }
        if (nproc > lastnproc) {
-               free(pt);
-               if ((pt =
-                   malloc((nproc + 1) * sizeof(struct p_times))) == NULL) {
+               if (reallocarr(&pt, nproc + 1, sizeof(struct p_times)) != 0) {
                        error("Out of memory");
                        die(0);
                }
diff -r ccea04594f21 -r bf028fc5eeed usr.bin/systat/swap.c
--- a/usr.bin/systat/swap.c     Mon Nov 08 23:57:23 2021 +0000
+++ b/usr.bin/systat/swap.c     Tue Nov 09 09:18:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: swap.c,v 1.20 2008/05/30 02:29:37 mrg Exp $    */
+/*     $NetBSD: swap.c,v 1.21 2021/11/09 09:18:02 nia Exp $    */
 
 /*
  * Copyright (c) 1997 Matthew R. Green.
@@ -60,7 +60,7 @@
 #if 0
 static char sccsid[] = "@(#)swap.c     8.3 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: swap.c,v 1.20 2008/05/30 02:29:37 mrg Exp $");
+__RCSID("$NetBSD: swap.c,v 1.21 2021/11/09 09:18:02 nia Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -121,10 +121,8 @@
                return;
        update_label = (nswap != rnswap);
 
-       if (swap_devices)
-               (void)free(swap_devices);
-       if ((swap_devices = malloc(nswap * sizeof(*swap_devices))) == NULL) {
-               error("malloc failed");
+       if (reallocarr(&swap_devices, nswap, sizeof(*swap_devices)) != 0) {
+               error("realloc failed");
                die(0);
        }
 



Home | Main Index | Thread Index | Old Index