Source-Changes-HG archive

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

[src/netbsd-1-4]: src/usr.bin/telnet Pull up revision 1.14 (requested by itoj...



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

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

diffstat:

 usr.bin/telnet/telnet.c |  23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diffs (53 lines):

diff -r 6627544d7b9d -r 0a4bebc2ef5f usr.bin/telnet/telnet.c
--- a/usr.bin/telnet/telnet.c   Sat Jan 08 18:09:00 2000 +0000
+++ b/usr.bin/telnet/telnet.c   Sat Jan 08 18:09:59 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: telnet.c,v 1.12 1998/11/06 19:54:19 christos Exp $     */
+/*     $NetBSD: telnet.c,v 1.12.2.1 2000/01/08 18:09:59 he Exp $       */
 
 /*
  * Copyright (c) 1988, 1990, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)telnet.c   8.4 (Berkeley) 5/30/95";
 #else
-__RCSID("$NetBSD: telnet.c,v 1.12 1998/11/06 19:54:19 christos Exp $");
+__RCSID("$NetBSD: telnet.c,v 1.12.2.1 2000/01/08 18:09:59 he Exp $");
 #endif
 #endif /* not lint */
 
@@ -1529,10 +1529,15 @@
        void
 env_opt_start()
 {
-       if (opt_reply)
-               opt_reply = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
-       else
-               opt_reply = (unsigned char *)malloc(OPT_REPLY_SIZE);
+       unsigned char *p;
+
+       if (opt_reply) {
+               p = (unsigned char *)realloc(opt_reply, OPT_REPLY_SIZE);
+               if (p == NULL)
+                       free(opt_reply);
+       } else
+               p = (unsigned char *)malloc(OPT_REPLY_SIZE);
+       opt_reply = p;
        if (opt_reply == NULL) {
 /*@*/          printf("env_opt_start: malloc()/realloc() failed!!!\n");
                opt_reply = opt_replyp = opt_replyend = NULL;
@@ -1580,9 +1585,13 @@
                                strlen((char *)ep) + 6 > opt_replyend)
        {
                register int len;
+               unsigned char *p;
                opt_replyend += OPT_REPLY_SIZE;
                len = opt_replyend - opt_reply;
-               opt_reply = (unsigned char *)realloc(opt_reply, len);
+               p = (unsigned char *)realloc(opt_reply, len);
+               if (p == NULL)
+                       free(opt_reply);
+               opt_reply = p;
                if (opt_reply == NULL) {
 /*@*/                  printf("env_opt_add: realloc() failed!!!\n");
                        opt_reply = opt_replyp = opt_replyend = NULL;



Home | Main Index | Thread Index | Old Index