Index: packages/net/common/current/ChangeLog =================================================================== RCS file: /cvs/ecos/ecos-opt/net/net/common/current/ChangeLog,v retrieving revision 1.40 diff -u -5 -p -r1.40 ChangeLog --- packages/net/common/current/ChangeLog 31 Jul 2003 08:56:26 -0000 1.40 +++ packages/net/common/current/ChangeLog 16 Sep 2003 21:36:18 -0000 @@ -1,5 +1,10 @@ +2003-09-16 Jay Foster + + * src/ifaddrs.c (getifaddrs): Fix up allocation and freeing of + work buffers and data buffers. + 2003-07-29 Motoya Kurotsu * src/dhcp_prot.c (do_dhcp): (re)Initialize the lease when dhcp is (re)initialized or retried. Return true when the state falls into DHCPSTATE_NOTBOUND so that it Index: packages/net/common/current/src/ifaddrs.c =================================================================== RCS file: /cvs/ecos/ecos-opt/net/net/common/current/src/ifaddrs.c,v retrieving revision 1.4 diff -u -5 -p -r1.4 ifaddrs.c --- packages/net/common/current/src/ifaddrs.c 12 May 2003 10:58:10 -0000 1.4 +++ packages/net/common/current/src/ifaddrs.c 16 Sep 2003 21:36:18 -0000 @@ -102,11 +102,12 @@ int getifaddrs(struct ifaddrs **pif) { int icnt = 1; // Interface count int dcnt = 0; // Data [length] count int ncnt = 0; // Length of interface names - char buf[1024]; + char *buf; +#define IF_WORK_SPACE_SZ 1024 int i, sock; #ifdef CYGPKG_NET_INET6 int sock6; struct in6_ifreq ifrq6; #endif @@ -114,19 +115,26 @@ getifaddrs(struct ifaddrs **pif) struct ifreq *ifr, *lifr; struct ifreq ifrq; char *data, *names; struct ifaddrs *ifa, *ift; + buf = malloc(IF_WORK_SPACE_SZ); + if (buf == NULL) + return (-1); ifc.ifc_buf = buf; - ifc.ifc_len = sizeof(buf); + ifc.ifc_len = IF_WORK_SPACE_SZ; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + { + free(buf); return (-1); + } i = ioctl(sock, SIOCGIFCONF, (char *)&ifc); if (i < 0) { close(sock); + free(buf); return (-1); } ifr = ifc.ifc_req; lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; @@ -165,14 +173,15 @@ getifaddrs(struct ifaddrs **pif) memset(ifa, 0, sizeof(struct ifaddrs) * icnt); ift = ifa; ifr = ifc.ifc_req; - lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len]; #ifdef CYGPKG_NET_INET6 if ((sock6 = socket(AF_INET6, SOCK_STREAM, 0)) < 0) { + free(buf); + free(data); close(sock); return (-1); } #endif @@ -232,10 +241,11 @@ getifaddrs(struct ifaddrs **pif) ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa)); else ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa)); ift = (ift->ifa_next = ift + 1); } + free(buf); if (--ift >= ifa) { ift->ifa_next = NULL; *pif = ifa; } else {