summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-16 21:20:08 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-16 21:20:08 +0000
commit1c6ff3b71d87ee1764e62ffbbc57b3ec543ef219 (patch)
treec0c41d6e44c56c35fbda00c007957567235808f1 /usr.sbin
parent976c506be0a96c2303d0f33a3a62aabcf564690c (diff)
fix realloc memory leaks
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/named/named-xfer/named-xfer.c12
-rw-r--r--usr.sbin/named/named/ns_main.c14
2 files changed, 15 insertions, 11 deletions
diff --git a/usr.sbin/named/named-xfer/named-xfer.c b/usr.sbin/named/named-xfer/named-xfer.c
index c8be29db6a9..ba4b5cdf887 100644
--- a/usr.sbin/named/named-xfer/named-xfer.c
+++ b/usr.sbin/named/named-xfer/named-xfer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: named-xfer.c,v 1.6 1998/05/22 07:09:23 millert Exp $ */
+/* $OpenBSD: named-xfer.c,v 1.7 1998/08/16 21:20:03 millert Exp $ */
/*
* The original version of xfer by Kevin Dunlap.
@@ -97,7 +97,7 @@ char copyright[] =
static char sccsid[] = "@(#)named-xfer.c 4.18 (Berkeley) 3/7/91";
static char rcsid[] = "$From: named-xfer.c,v 8.24 1998/04/07 04:59:45 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: named-xfer.c,v 1.6 1998/05/22 07:09:23 millert Exp $";
+static char rcsid[] = "$OpenBSD: named-xfer.c,v 1.7 1998/08/16 21:20:03 millert Exp $";
#endif
#endif /* not lint */
@@ -665,7 +665,7 @@ getzone(zp, serial_no, port)
continue;
}
if (len > bufsize) {
- if ((buf = (u_char *)realloc(buf, len)) == NULL) {
+ if ((tmp = (u_char *)realloc(buf, len)) == NULL) {
syslog(LOG_INFO,
"malloc(%u) failed for SOA from server [%s], zone %s\n",
len,
@@ -674,6 +674,7 @@ getzone(zp, serial_no, port)
(void) my_close(s);
continue;
}
+ buf = tmp;
bufsize = len;
}
if (netread(s, (char *)buf, len, XFER_TIMER) < 0) {
@@ -906,8 +907,8 @@ getzone(zp, serial_no, port)
if ((len = _getshort(buf)) == 0)
break;
if (len > bufsize) {
- buf = (u_char *)realloc(buf, len);
- if (buf == NULL) {
+ tmp = (u_char *)realloc(buf, len);
+ if (tmp == NULL) {
syslog(LOG_INFO,
"malloc(%u) failed for packet from server [%s], zone %s\n",
len,
@@ -916,6 +917,7 @@ getzone(zp, serial_no, port)
error++;
break;
}
+ buf = tmp;
bufsize = len;
}
hp = (HEADER *)buf;
diff --git a/usr.sbin/named/named/ns_main.c b/usr.sbin/named/named/ns_main.c
index b3a56022b79..6a243a18463 100644
--- a/usr.sbin/named/named/ns_main.c
+++ b/usr.sbin/named/named/ns_main.c
@@ -1,11 +1,11 @@
-/* $OpenBSD: ns_main.c,v 1.15 1998/08/14 15:07:36 millert Exp $ */
+/* $OpenBSD: ns_main.c,v 1.16 1998/08/16 21:20:07 millert Exp $ */
#if !defined(lint) && !defined(SABER)
#if 0
static char sccsid[] = "@(#)ns_main.c 4.55 (Berkeley) 7/1/91";
static char rcsid[] = "$From: ns_main.c,v 8.26 1998/05/11 04:19:45 vixie Exp $";
#else
-static char rcsid[] = "$OpenBSD: ns_main.c,v 1.15 1998/08/14 15:07:36 millert Exp $";
+static char rcsid[] = "$OpenBSD: ns_main.c,v 1.16 1998/08/16 21:20:07 millert Exp $";
#endif
#endif /* not lint */
@@ -1037,14 +1037,16 @@ main(argc, argv, envp)
if (sp->s_size > sp->s_bufsize &&
sp->s_bufsize != 0
) {
- sp->s_buf = (u_char *)
- realloc((char *)sp->s_buf,
- (unsigned)sp->s_size);
- if (sp->s_buf == NULL) {
+ u_char *s_buf = (u_char *)
+ realloc((void *)sp->s_buf,
+ (size_t)sp->s_size);
+ if (s_buf == NULL) {
+ free(sp->s_buf);
sp->s_buf = buf;
sp->s_bufsize = 0;
sp->s_size = sizeof(buf);
} else {
+ sp->s_buf = s_buf;
sp->s_bufsize = sp->s_size;
}
}