Skip to content

zbeacon: fix socket leak #2002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/zbeacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ s_self_destroy (self_t **self_p)
self_t *self = *self_p;
zframe_destroy (&self->transmit);
zframe_destroy (&self->filter);
if (self->udpsock) // don't close STDIN
if (self->udpsock != INVALID_SOCKET)
zsys_udp_close (self->udpsock);
if (self->udpsock_send != INVALID_SOCKET)
zsys_udp_close (self->udpsock_send);
freen (self);
*self_p = NULL;
}
Expand All @@ -69,6 +71,8 @@ s_self_new (zsock_t *pipe)
self_t *self = (self_t *) zmalloc (sizeof (self_t));
assert (self);
self->pipe = pipe;
self->udpsock = INVALID_SOCKET;
self->udpsock_send = INVALID_SOCKET;
return self;
}

Expand All @@ -80,9 +84,9 @@ static void
s_self_prepare_udp (self_t *self)
{
// Create our UDP socket
if (self->udpsock)
if (self->udpsock != INVALID_SOCKET)
zsys_udp_close (self->udpsock);
if (self->udpsock_send)
if (self->udpsock_send != INVALID_SOCKET)
zsys_udp_close (self->udpsock_send);

self->hostname [0] = 0;
Expand Down