diff options
author | Rob Landley <rob@landley.net> | 2006-02-22 02:10:34 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-02-22 02:10:34 +0000 |
commit | e8f504e86d90b85d85f6005fa8e53a45385d07c8 (patch) | |
tree | 0d8962e3c3bc86d129c9fba431204dfb43c3cc48 | |
parent | d6e14d8beebb5c9571bded30df6568570f0c2a54 (diff) | |
download | busybox-w32-e8f504e86d90b85d85f6005fa8e53a45385d07c8.tar.gz busybox-w32-e8f504e86d90b85d85f6005fa8e53a45385d07c8.tar.bz2 busybox-w32-e8f504e86d90b85d85f6005fa8e53a45385d07c8.zip |
Bug 751: file handle leaks can add up until available filehandles for the
process are exhausted.
-rw-r--r-- | networking/udhcp/packet.c | 12 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 3 |
2 files changed, 12 insertions, 3 deletions
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 1baec55e2..222dd24e0 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
@@ -177,24 +177,30 @@ int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_po | |||
177 | if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) | 177 | if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) |
178 | return -1; | 178 | return -1; |
179 | 179 | ||
180 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) | 180 | if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) { |
181 | close(fd); | ||
181 | return -1; | 182 | return -1; |
183 | } | ||
182 | 184 | ||
183 | memset(&client, 0, sizeof(client)); | 185 | memset(&client, 0, sizeof(client)); |
184 | client.sin_family = AF_INET; | 186 | client.sin_family = AF_INET; |
185 | client.sin_port = htons(source_port); | 187 | client.sin_port = htons(source_port); |
186 | client.sin_addr.s_addr = source_ip; | 188 | client.sin_addr.s_addr = source_ip; |
187 | 189 | ||
188 | if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) | 190 | if (bind(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) { |
191 | close(fd); | ||
189 | return -1; | 192 | return -1; |
193 | } | ||
190 | 194 | ||
191 | memset(&client, 0, sizeof(client)); | 195 | memset(&client, 0, sizeof(client)); |
192 | client.sin_family = AF_INET; | 196 | client.sin_family = AF_INET; |
193 | client.sin_port = htons(dest_port); | 197 | client.sin_port = htons(dest_port); |
194 | client.sin_addr.s_addr = dest_ip; | 198 | client.sin_addr.s_addr = dest_ip; |
195 | 199 | ||
196 | if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) | 200 | if (connect(fd, (struct sockaddr *)&client, sizeof(struct sockaddr)) == -1) { |
201 | close(fd); | ||
197 | return -1; | 202 | return -1; |
203 | } | ||
198 | 204 | ||
199 | result = write(fd, payload, sizeof(struct dhcpMessage)); | 205 | result = write(fd, payload, sizeof(struct dhcpMessage)); |
200 | close(fd); | 206 | close(fd); |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 7b057523a..036885175 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -62,6 +62,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) | |||
62 | DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); | 62 | DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); |
63 | } else { | 63 | } else { |
64 | LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m"); | 64 | LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m"); |
65 | close(fd); | ||
65 | return -1; | 66 | return -1; |
66 | } | 67 | } |
67 | } | 68 | } |
@@ -71,6 +72,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) | |||
71 | *ifindex = ifr.ifr_ifindex; | 72 | *ifindex = ifr.ifr_ifindex; |
72 | } else { | 73 | } else { |
73 | LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m"); | 74 | LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m"); |
75 | close(fd); | ||
74 | return -1; | 76 | return -1; |
75 | } | 77 | } |
76 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) { | 78 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) { |
@@ -79,6 +81,7 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) | |||
79 | arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); | 81 | arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); |
80 | } else { | 82 | } else { |
81 | LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m"); | 83 | LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m"); |
84 | close(fd); | ||
82 | return -1; | 85 | return -1; |
83 | } | 86 | } |
84 | } else { | 87 | } else { |