Fixed compile warnings and a memory leak

Fixed -fPIC warnings and unused function warnings on GCC. 

Fixed fr::TcpSocket not calling freeaddrinfo() on failure to connect, causing a small leak.
This commit is contained in:
Fred Nicolson 2017-12-01 10:59:00 +00:00
parent 8bef6df130
commit b574800a0a
4 changed files with 10 additions and 7 deletions

View File

@ -45,7 +45,7 @@ if(USE_SSL)
endif()
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread")
endif()
# Set the library output directory

View File

@ -21,7 +21,10 @@
#include <ws2tcpip.h>
#define SOL_TCP SOL_SOCKET
#define SHUT_RDWR SD_BOTH
#define UNUSED_VAR
#else
#define UNUSED_VAR __attribute__ ((unused))
#define closesocket(x) close(x)
#define INVALID_SOCKET 0
#define SOCKET_ERROR (-1)
@ -95,7 +98,7 @@ inline void set_unix_socket_blocking(int32_t socket_descriptor, bool is_blocking
#endif
}
static void init_wsa()
static UNUSED_VAR void init_wsa()
{
#ifdef _WIN32
static WSADATA wsaData = WSAData();

View File

@ -20,8 +20,8 @@ namespace fr
{
public:
Packet() noexcept
: buffer_read_index(PACKET_HEADER_LENGTH),
buffer(PACKET_HEADER_LENGTH, '0')
: buffer(PACKET_HEADER_LENGTH, '0'),
buffer_read_index(PACKET_HEADER_LENGTH)
{
}

View File

@ -117,12 +117,12 @@ namespace fr
break;
}
if(c == nullptr)
return Socket::Status::Error;
//We're done with this now, cleanup
freeaddrinfo(info);
if(c == nullptr)
return Socket::Status::Error;
//Update state now we've got a valid socket descriptor
remote_address = address + ":" + port;
reconfigure_socket();