summaryrefslogtreecommitdiff
path: root/networking/udhcp/packet.c
diff options
context:
space:
mode:
authorRob Landley2006-02-22 02:10:34 +0000
committerRob Landley2006-02-22 02:10:34 +0000
commite8f504e86d90b85d85f6005fa8e53a45385d07c8 (patch)
tree0d8962e3c3bc86d129c9fba431204dfb43c3cc48 /networking/udhcp/packet.c
parentd6e14d8beebb5c9571bded30df6568570f0c2a54 (diff)
downloadbusybox-e8f504e86d90b85d85f6005fa8e53a45385d07c8.zip
busybox-e8f504e86d90b85d85f6005fa8e53a45385d07c8.tar.gz
Bug 751: file handle leaks can add up until available filehandles for the
process are exhausted.
Diffstat (limited to 'networking/udhcp/packet.c')
-rw-r--r--networking/udhcp/packet.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 1baec55..222dd24 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
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);