svn commit: trunk/busybox/networking/udhcp

landley at busybox.net landley at busybox.net
Wed Feb 22 02:10:34 UTC 2006


Author: landley
Date: 2006-02-21 18:10:34 -0800 (Tue, 21 Feb 2006)
New Revision: 14178

Log:
Bug 751: file handle leaks can add up until available filehandles for the
process are exhausted.


Modified:
   trunk/busybox/networking/udhcp/packet.c
   trunk/busybox/networking/udhcp/socket.c


Changeset:
Modified: trunk/busybox/networking/udhcp/packet.c
===================================================================
--- trunk/busybox/networking/udhcp/packet.c	2006-02-22 02:06:35 UTC (rev 14177)
+++ trunk/busybox/networking/udhcp/packet.c	2006-02-22 02:10:34 UTC (rev 14178)
@@ -177,24 +177,30 @@
 	if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
 		return -1;
 
-	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1)
+	if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
+		close(fd);
 		return -1;
+	}
 
 	memset(&client, 0, sizeof(client));
 	client.sin_family = AF_INET;
 	client.sin_port = htons(source_port);
 	client.sin_addr.s_addr = source_ip;
 
-	if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
+	if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) {
+		close(fd);
 		return -1;
+	}
 
 	memset(&client, 0, sizeof(client));
 	client.sin_family = AF_INET;
 	client.sin_port = htons(dest_port);
 	client.sin_addr.s_addr = dest_ip;
 
-	if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1)
+	if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) {
+		close(fd);
 		return -1;
+	}
 
 	result = write(fd, payload, sizeof(struct dhcpMessage));
 	close(fd);

Modified: trunk/busybox/networking/udhcp/socket.c
===================================================================
--- trunk/busybox/networking/udhcp/socket.c	2006-02-22 02:06:35 UTC (rev 14177)
+++ trunk/busybox/networking/udhcp/socket.c	2006-02-22 02:10:34 UTC (rev 14178)
@@ -62,6 +62,7 @@
 				DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
 			} else {
 				LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m");
+				close(fd);
 				return -1;
 			}
 		}
@@ -71,6 +72,7 @@
 			*ifindex = ifr.ifr_ifindex;
 		} else {
 			LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m");
+			close(fd);
 			return -1;
 		}
 		if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
@@ -79,6 +81,7 @@
 				arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
 		} else {
 			LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m");
+			close(fd);
 			return -1;
 		}
 	} else {




More information about the busybox-cvs mailing list