mirror of
https://github.com/zeromq/libzmq.git
synced 2025-01-16 20:41:18 +08:00
Merge pull request #574 from pijyoi/master
fix memory leak in ipc_listener wildcard
This commit is contained in:
commit
1195092c61
@ -119,19 +119,24 @@ int zmq::ipc_listener_t::get_address (std::string &addr_)
|
|||||||
|
|
||||||
int zmq::ipc_listener_t::set_address (const char *addr_)
|
int zmq::ipc_listener_t::set_address (const char *addr_)
|
||||||
{
|
{
|
||||||
|
// Create addr on stack for auto-cleanup
|
||||||
|
std::string addr (addr_);
|
||||||
|
|
||||||
// Allow wildcard file
|
// Allow wildcard file
|
||||||
if (*addr_ == '*') {
|
if (addr[0] == '*') {
|
||||||
addr_ = tempnam(NULL, NULL);
|
char *tmpstr = tempnam (NULL, NULL);
|
||||||
|
addr.assign (tmpstr);
|
||||||
|
free (tmpstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get rid of the file associated with the UNIX domain socket that
|
// Get rid of the file associated with the UNIX domain socket that
|
||||||
// may have been left behind by the previous run of the application.
|
// may have been left behind by the previous run of the application.
|
||||||
::unlink (addr_);
|
::unlink (addr.c_str());
|
||||||
filename.clear ();
|
filename.clear ();
|
||||||
|
|
||||||
// Initialise the address structure.
|
// Initialise the address structure.
|
||||||
ipc_address_t address;
|
ipc_address_t address;
|
||||||
int rc = address.resolve (addr_);
|
int rc = address.resolve (addr.c_str());
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -147,10 +152,10 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
|
|||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
filename.assign(addr_);
|
filename.assign (addr.c_str());
|
||||||
has_file = true;
|
has_file = true;
|
||||||
|
|
||||||
// Listen for incomming connections.
|
// Listen for incoming connections.
|
||||||
rc = listen (s, options.backlog);
|
rc = listen (s, options.backlog);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user