Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.sbin/rwhod Pull up revision 1.17 (requested by itoj...



details:   https://anonhg.NetBSD.org/src/rev/6627544d7b9d
branches:  netbsd-1-4
changeset: 469985:6627544d7b9d
user:      he <he%NetBSD.org@localhost>
date:      Sat Jan 08 18:09:00 2000 +0000

description:
Pull up revision 1.17 (requested by itojun):
  Avoid memory leak on realloc() failure.

diffstat:

 usr.sbin/rwhod/rwhod.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (41 lines):

diff -r aef3940913f4 -r 6627544d7b9d usr.sbin/rwhod/rwhod.c
--- a/usr.sbin/rwhod/rwhod.c    Sat Jan 08 18:05:41 2000 +0000
+++ b/usr.sbin/rwhod/rwhod.c    Sat Jan 08 18:09:00 2000 +0000
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)rwhod.c    8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: rwhod.c,v 1.14.2.1 1999/11/20 17:22:20 he Exp $");
+__RCSID("$NetBSD: rwhod.c,v 1.14.2.2 2000/01/08 18:09:00 he Exp $");
 #endif
 #endif /* not lint */
 
@@ -281,6 +281,7 @@
        struct stat stb;
        double avenrun[3];
        time_t now;
+       struct utmp *nutmp;
        int cc;
 
        now = time(NULL);
@@ -293,14 +294,17 @@
                if (stb.st_size > utmpsize) {
                        utmpsize = stb.st_size + 10 * sizeof(struct utmp);
                        if (utmp)
-                               utmp = (struct utmp *)realloc(utmp, utmpsize);
+                               nutmp = (struct utmp *)realloc(utmp, utmpsize);
                        else
-                               utmp = (struct utmp *)malloc(utmpsize);
-                       if (! utmp) {
+                               nutmp = (struct utmp *)malloc(utmpsize);
+                       if (! nutmp) {
                                warn("malloc failed");
+                               if (utmp)
+                                       free(utmp);
                                utmpsize = 0;
                                goto done;
                        }
+                       utmp = nutmp;
                }
                (void)lseek(utmpf, (off_t)0, SEEK_SET);
                cc = read(utmpf, (char *)utmp, stb.st_size);



Home | Main Index | Thread Index | Old Index