Skip to content

Commit

Permalink
Fixed cleanup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen van der Heijden committed Sep 11, 2017
1 parent 31cb283 commit b543dac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
libsuv (0.1.2)

* Fixed bug in cleanup.

-- Jeroen van der Heijden <[email protected]> 11 Sep 2017

libsuv (0.1.1)

* Cleanup connection when connect has failed.
Expand Down
18 changes: 10 additions & 8 deletions suv.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ void suv_connect(
struct sockaddr * addr)
{
assert (connect->_req->data == connect); /* bind connect to req->data */
assert (buf->siridb->data == NULL); /* siridb data should be null, maybe
the connection is still in use? */

uv_connect_t * uvreq = (uv_connect_t *) malloc(sizeof(uv_connect_t));
if (uvreq == NULL)
Expand Down Expand Up @@ -135,13 +133,13 @@ void suv_connect(
void suv_close(suv_buf_t * buf, const char * msg)
{
uv_tcp_t * tcp_ = (uv_tcp_t *) buf->siridb->data;
if (!uv_is_closing((uv_handle_t *) tcp_))
if (tcp_ != NULL && !uv_is_closing((uv_handle_t *) tcp_))
{
if (buf->onclose != NULL)
{
buf->onclose(buf->data, (msg == NULL) ? "connection closed" : msg);
}
suv__close_tcp((uv_handle_t *) tcp_);
uv_close((uv_handle_t *) tcp_, suv__close_tcp);
}
}

Expand Down Expand Up @@ -246,9 +244,12 @@ static void suv__close_tcp(uv_handle_t * tcp)
if (tcp->data != NULL)
{
suv_buf_t * buf = (suv_buf_t *) tcp->data;
buf->siridb->data = NULL;
if (tcp == (uv_handle_t *) buf->siridb->data)
{
buf->siridb->data = NULL;
}
}
uv_close(tcp, (uv_close_cb) free);
free(tcp);
}

/*
Expand Down Expand Up @@ -318,15 +319,16 @@ static void suv__connect_cb(uv_connect_t * uvreq, int status)
{
/* error handling */
suv_write_error((suv_write_t *) connect, -status);
suv__close_tcp((uv_handle_t *) connect->_req->siridb->data);
uv_close((uv_handle_t *) connect->_req->siridb->data, suv__close_tcp);
}
else
{
uv_write_t * uvw = (uv_write_t *) malloc(sizeof(uv_write_t));
if (uvw == NULL)
{
suv_write_error((suv_write_t *) connect, ERR_MEM_ALLOC);
suv__close_tcp((uv_handle_t *) connect->_req->siridb->data);
uv_close(
(uv_handle_t *) connect->_req->siridb->data, suv__close_tcp);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion suv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define SUV_VERSION_MAJOR 0
#define SUV_VERSION_MINOR 1
#define SUV_VERSION_PATCH 1
#define SUV_VERSION_PATCH 2

#define SUV_STRINGIFY(num) #num
#define SUV_VERSION_STR(major,minor,patch) \
Expand Down

0 comments on commit b543dac

Please sign in to comment.