summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1998-08-17 06:42:40 +0000
committerbrian <brian@FreeBSD.org>1998-08-17 06:42:40 +0000
commitab64c29a02182ed0b56085a9d7e5956e425a3fe4 (patch)
treee85b57f0dca8b91b2acf47d557181be3e44a8933
parent49f35df526d2d6fc7e1e864c8b620a9368285eca (diff)
downloadFreeBSD-src-ab64c29a02182ed0b56085a9d7e5956e425a3fe4.zip
FreeBSD-src-ab64c29a02182ed0b56085a9d7e5956e425a3fe4.tar.gz
Don't lose an allocated pointer if realloc() fails.
Free it instead. Pointed out by: Theo de Raadt
-rw-r--r--usr.sbin/ppp/route.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c
index 0f7f019..a80204d 100644
--- a/usr.sbin/ppp/route.c
+++ b/usr.sbin/ppp/route.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: route.c,v 1.51 1998/06/27 23:48:53 brian Exp $
+ * $Id: route.c,v 1.52 1998/07/28 21:54:54 brian Exp $
*
*/
@@ -236,17 +236,22 @@ Index2Nam(int idx)
dl = (struct sockaddr_dl *)(ifm + 1);
if (ifm->ifm_index > 0) {
if (ifm->ifm_index > have) {
+ char **newifs;
+
had = have;
have = ifm->ifm_index + 5;
if (had)
- ifs = (char **)realloc(ifs, sizeof(char *) * have);
+ newifs = (char **)realloc(ifs, sizeof(char *) * have);
else
- ifs = (char **)malloc(sizeof(char *) * have);
- if (!ifs) {
+ newifs = (char **)malloc(sizeof(char *) * have);
+ if (!newifs) {
log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno));
nifs = 0;
+ if (ifs)
+ free(ifs);
return "???";
}
+ ifs = newifs;
memset(ifs + had, '\0', sizeof(char *) * (have - had));
}
if (ifs[ifm->ifm_index-1] == NULL) {
OpenPOWER on IntegriCloud