diff options
author | Thomas Huth <thuth@redhat.com> | 2016-09-19 21:08:23 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2016-10-10 17:30:54 +1100 |
commit | 265ee13712b191e51bc932c27e95f3acba6b8121 (patch) | |
tree | 3217e7b10953453d4a28282422a8f5f0dfff6310 /lib | |
parent | 13ed4d27756b2e970c662c05da66bcd89b6df543 (diff) | |
download | SLOF-265ee13712b191e51bc932c27e95f3acba6b8121.zip SLOF-265ee13712b191e51bc932c27e95f3acba6b8121.tar.gz SLOF-265ee13712b191e51bc932c27e95f3acba6b8121.tar.bz2 |
libnet: Make sure to close sockets when we're done
If libnet is linked to the net-snk, it does not matter since the
whole stack is completely reloaded each time. But if we are
linking libnet to Paflof, we've got to make sure to properly
release the resources that we've allocated before, since the
code and data stays in memory.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libnet/netload.c | 6 | ||||
-rw-r--r-- | lib/libnet/ping.c | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c index d99aa29..7ded3e4 100644 --- a/lib/libnet/netload.c +++ b/lib/libnet/netload.c @@ -10,6 +10,7 @@ * IBM Corporation - initial implementation *****************************************************************************/ +#include <unistd.h> #include <tftp.h> #include <ethernet.h> #include <dhcp.h> @@ -566,6 +567,7 @@ netboot(int argc, char *argv[]) bootmsg_error(0x3001, &buf[7]); write_mm_log(buf, strlen(buf), 0x91); + close(fn_ip.fd); return -101; } @@ -590,6 +592,7 @@ netboot(int argc, char *argv[]) bootmsg_error(0x3002, &buf[7]); write_mm_log(buf, strlen(buf), 0x91); + close(fn_ip.fd); return -102; } if (rc == -4 || rc == -3) { @@ -597,6 +600,7 @@ netboot(int argc, char *argv[]) bootmsg_error(0x3008, &buf[7]); write_mm_log(buf, strlen(buf), 0x91); + close(fn_ip.fd); return -107; } @@ -635,6 +639,8 @@ netboot(int argc, char *argv[]) if(obp_tftp_args.ip_init == IP_INIT_DHCP) dhcp_send_release(fn_ip.fd); + close(fn_ip.fd); + if (rc > 0) { printf(" TFTP: Received %s (%d KBytes)\n", fn_ip.filename, rc / 1024); diff --git a/lib/libnet/ping.c b/lib/libnet/ping.c index def3179..2b6a1d7 100644 --- a/lib/libnet/ping.c +++ b/lib/libnet/ping.c @@ -10,6 +10,7 @@ * IBM Corporation - initial implementation *****************************************************************************/ +#include <unistd.h> #include <ipv4.h> #include <dhcp.h> #include <ethernet.h> @@ -160,6 +161,7 @@ ping(int argc, char *argv[]) if (arp_failed == -1) { printf("\n DHCP: Could not get ip address\n"); + close(fn_ip.fd); return -1; } @@ -206,10 +208,12 @@ ping(int argc, char *argv[]) receive_ether(fd_device); if(pong_ipv4() == 0) { printf("success\n"); + close(fn_ip.fd); return 0; } } printf("failed\n"); + close(fn_ip.fd); return -1; } |