Skip to content

Commit

Permalink
fix(invalid-free): fixed invalid free of connection
Browse files Browse the repository at this point in the history
  • Loading branch information
martinopresnik committed Jun 6, 2018
1 parent 43cc99b commit 85e53cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/bproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ void conn_close(conn_t *conn)
{
if (conn->proxy_handle)
{
if (!uv_is_closing((uv_handle_t *)conn->proxy_handle) && !uv_is_active((uv_handle_t *)conn->proxy_handle))
if (!uv_is_closing((uv_handle_t *)conn->proxy_handle))
{
uv_close((uv_handle_t *)conn->proxy_handle, proxy_close_cb);
conn->proxy_handle = NULL;
}
}
if (conn->handle)
Expand All @@ -191,7 +190,7 @@ void conn_close(conn_t *conn)
free(bq->buf.base);
}
http_free_raw_requests_queue(&conn->http_link_context.request);
// free(conn);
free(conn);
}
}

Expand Down Expand Up @@ -285,17 +284,17 @@ void proxy_connect_cb(uv_connect_t *req, int status)
{
conn_close(conn);
// TODO: write meaningful responses
return;
}

uv_read_start((uv_stream_t *)conn->proxy_handle, alloc_cb, proxy_read_cb);
// http_request_t *request = &conn->http_link_context.request;
// write_buf((uv_stream_t *)conn->proxy_handle, request->raw, request->raw_len);
QUEUE *q;
QUEUE_FOREACH(q, &conn->http_link_context.request.raw_requests)
{
buf_queue_t *bq = QUEUE_DATA(q, buf_queue_t, member);
write_buf((uv_stream_t *)conn->proxy_handle, bq->buf.base, bq->buf.len);
if (status >= 0)
{
write_buf((uv_stream_t *)conn->proxy_handle, bq->buf.base, bq->buf.len);
}
free(bq->buf.base);
}
http_free_raw_requests_queue(&conn->http_link_context.request);
Expand Down
2 changes: 1 addition & 1 deletion src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void http_init_response_headers(http_response_t *response, bool compressed)
strcat(response->http_header, "Transfer-Encoding: chunked\r\n");
strcat(response->http_header, "Content-Encoding: gzip\r\n");
}
char *name_and_version = malloc(sizeof(char) * 100);
char name_and_version[100];
sprintf(name_and_version, "Via: bproxy %s\r\n\r\n", VERSION);
strcat(response->http_header, name_and_version);
response->http_header_len = strlen(response->http_header);
Expand Down

0 comments on commit 85e53cc

Please sign in to comment.