Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/netstat Allocate the right size for pcb blocks.



details:   https://anonhg.NetBSD.org/src/rev/6a9d396af03e
branches:  trunk
changeset: 806187:6a9d396af03e
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Feb 08 15:09:45 2015 +0000

description:
Allocate the right size for pcb blocks.
XXX: pullup-7!

diffstat:

 usr.bin/netstat/inet.c  |  10 ++++++----
 usr.bin/netstat/inet6.c |  10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)

diffs (76 lines):

diff -r 2761b4f368f3 -r 6a9d396af03e usr.bin/netstat/inet.c
--- a/usr.bin/netstat/inet.c    Sun Feb 08 14:46:30 2015 +0000
+++ b/usr.bin/netstat/inet.c    Sun Feb 08 15:09:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet.c,v 1.105 2015/02/07 19:36:06 christos Exp $      */
+/*     $NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $      */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)inet.c       8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet.c,v 1.105 2015/02/07 19:36:06 christos Exp $");
+__RCSID("$NetBSD: inet.c,v 1.106 2015/02/08 15:09:45 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -286,7 +286,7 @@
        next = TAILQ_FIRST(head);
        prev = TAILQ_END(head);
 
-       if ((pcblist = malloc(size)) == NULL)
+       if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
                err(1, "malloc");
 
        i = 0;
@@ -317,7 +317,9 @@
                pcblist[i].ki_tstate = tcpcb.t_state;
                pcblist[i].ki_pflags = inpcb.inp_flags;
                if (i++ == size) {
-                       struct kinfo_pcb *n = realloc(pcblist, size += 100);
+                       size += 100;
+                       struct kinfo_pcb *n = realloc(pcblist,
+                           size * sizeof(*pcblist));
                        if (n == NULL)
                                err(1, "realloc");
                        pcblist = n;
diff -r 2761b4f368f3 -r 6a9d396af03e usr.bin/netstat/inet6.c
--- a/usr.bin/netstat/inet6.c   Sun Feb 08 14:46:30 2015 +0000
+++ b/usr.bin/netstat/inet6.c   Sun Feb 08 15:09:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: inet6.c,v 1.67 2015/02/07 19:36:06 christos Exp $      */
+/*     $NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $      */
 /*     BSDI inet.c,v 2.3 1995/10/24 02:19:29 prb Exp   */
 
 /*
@@ -64,7 +64,7 @@
 #if 0
 static char sccsid[] = "@(#)inet.c     8.4 (Berkeley) 4/20/94";
 #else
-__RCSID("$NetBSD: inet6.c,v 1.67 2015/02/07 19:36:06 christos Exp $");
+__RCSID("$NetBSD: inet6.c,v 1.68 2015/02/08 15:09:45 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -303,7 +303,7 @@
        next = TAILQ_FIRST(head);
        prev = TAILQ_END(head);
 
-       if ((pcblist = malloc(size)) == NULL)
+       if ((pcblist = malloc(size * sizeof(*pcblist))) == NULL)
                err(1, "malloc");
 
        i = 0;
@@ -338,7 +338,9 @@
                memcpy(&pcblist[i].ki_d, &sin6, sizeof(sin6));
                pcblist[i].ki_tstate = tcpcb.t_state;
                if (i++ == size) {
-                       struct kinfo_pcb *n = realloc(pcblist, size += 100);
+                       size += 100;
+                       struct kinfo_pcb *n = realloc(pcblist,
+                           size * sizeof(*pcblist));
                        if (n == NULL)
                                err(1, "realloc");
                        pcblist = n;



Home | Main Index | Thread Index | Old Index