From 5067359ed712d05a2f0c85e3797c7d6a01c1dbff Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 2015 08:39:16 +1000 Subject: [PATCH] AP_HAL: fixed socket destructor --- libraries/AP_HAL/utility/Socket.cpp | 5 +++-- libraries/AP_HAL/utility/Socket.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/AP_HAL/utility/Socket.cpp b/libraries/AP_HAL/utility/Socket.cpp index 501b8dd18a..331ba28631 100644 --- a/libraries/AP_HAL/utility/Socket.cpp +++ b/libraries/AP_HAL/utility/Socket.cpp @@ -35,8 +35,9 @@ datagram(_datagram) SocketAPM::~SocketAPM() { - if (::close(fd) < 0) { - perror("close"); + if (fd != -1) { + ::close(fd); + fd = -1; } } diff --git a/libraries/AP_HAL/utility/Socket.h b/libraries/AP_HAL/utility/Socket.h index 32b9be87cd..c090ba0a45 100644 --- a/libraries/AP_HAL/utility/Socket.h +++ b/libraries/AP_HAL/utility/Socket.h @@ -47,7 +47,7 @@ public: private: bool datagram; - int fd; + int fd = -1; void make_sockaddr(const char *address, uint16_t port, struct sockaddr_in &sockaddr); };