summaryrefslogtreecommitdiffstats
path: root/src/socket
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-05-12 00:02:38 +0000
committerDavid Robillard <d@drobilla.net>2012-05-12 00:02:38 +0000
commiteaf3abc571e5c1a60cf6d65d55b3cc496d5e62dd (patch)
tree7a72b7bddc1278fa85773690d6d3cb30a2de6990 /src/socket
parentcaecf11ea7ced8e54992cc163b1b88f495f474cf (diff)
downloadingen-eaf3abc571e5c1a60cf6d65d55b3cc496d5e62dd.tar.gz
ingen-eaf3abc571e5c1a60cf6d65d55b3cc496d5e62dd.tar.bz2
ingen-eaf3abc571e5c1a60cf6d65d55b3cc496d5e62dd.zip
Fix memory leaks.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4364 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/socket')
-rw-r--r--src/socket/Socket.cpp8
-rw-r--r--src/socket/Socket.hpp2
2 files changed, 9 insertions, 1 deletions
diff --git a/src/socket/Socket.cpp b/src/socket/Socket.cpp
index 97411b64..9192217b 100644
--- a/src/socket/Socket.cpp
+++ b/src/socket/Socket.cpp
@@ -70,9 +70,16 @@ Socket::Socket(Type t,
{
}
+Socket::~Socket()
+{
+ free(_addr);
+ close();
+}
+
bool
Socket::set_addr(const std::string& uri)
{
+ free(_addr);
if (_type == UNIX && uri.substr(0, strlen("unix://")) == "unix://") {
const std::string path = uri.substr(strlen("unix://"));
struct sockaddr_un* uaddr = (struct sockaddr_un*)calloc(
@@ -105,6 +112,7 @@ Socket::set_addr(const std::string& uri)
_addr = (struct sockaddr*)malloc(ainfo->ai_addrlen);
_addr_len = ainfo->ai_addrlen;
memcpy(_addr, ainfo->ai_addr, ainfo->ai_addrlen);
+ freeaddrinfo(ainfo);
return true;
}
return false;
diff --git a/src/socket/Socket.hpp b/src/socket/Socket.hpp
index 8aa172cb..13f18be8 100644
--- a/src/socket/Socket.hpp
+++ b/src/socket/Socket.hpp
@@ -55,7 +55,7 @@ public:
socklen_t addr_len,
int fd);
- ~Socket() { close(); }
+ ~Socket();
/** Bind a server socket to an address.
* @param uri Address URI, e.g. unix:///tmp/foo or tcp://somehost:1234