diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 1999-12-30 16:58:23 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 1999-12-30 16:58:23 +0000 |
commit | b87682d493ecd7cd8e3912529e62f7ef10ef9676 (patch) | |
tree | 62ebfcadf7c444f3422204d047657f7d9cc592bb /usr.bin | |
parent | 66e82a8d9d801188a285a2bb783b76433bc90f38 (diff) |
avoid memory leak on realloc() failure.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/telnet/telnet.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/usr.bin/telnet/telnet.c b/usr.bin/telnet/telnet.c index 65ee77f1e64..0a3b80b20d7 100644 --- a/usr.bin/telnet/telnet.c +++ b/usr.bin/telnet/telnet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: telnet.c,v 1.7 1999/07/23 15:04:48 aaron Exp $ */ +/* $OpenBSD: telnet.c,v 1.8 1999/12/30 16:58:22 itojun Exp $ */ /* $NetBSD: telnet.c,v 1.7 1996/02/28 21:04:15 thorpej Exp $ */ /* @@ -1509,10 +1509,15 @@ unsigned char *opt_replyend; 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; @@ -1560,9 +1565,13 @@ env_opt_add(ep) 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; |