Skip to content

Commit

Permalink
inspector: fix Coverity defects
Browse files Browse the repository at this point in the history
One defect remains - Coverity believes that a session object is never
freed while in reality its lifespan is tied to a libuv socket.

PR-URL: #10240
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ali Ijaz Sheikh <[email protected]>
  • Loading branch information
Eugene Ostroukhov authored and evanlucas committed Jan 4, 2017
1 parent 0239561 commit 4bed947
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate,
int port) : loop_(nullptr),
delegate_(delegate),
port_(port),
server_(uv_tcp_t()),
closer_(nullptr),
next_session_id_(0) { }

Expand Down Expand Up @@ -400,6 +401,7 @@ void InspectorSocketServer::SocketConnectedCallback(uv_stream_t* server,
int status) {
if (status == 0) {
InspectorSocketServer* socket_server = InspectorSocketServer::From(server);
// Memory is freed when the socket closes.
SocketSession* session =
new SocketSession(socket_server, socket_server->next_session_id_++);
if (inspector_accept(server, session->Socket(), HandshakeCallback) != 0) {
Expand Down
10 changes: 5 additions & 5 deletions test/cctest/test_inspector_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ class InspectorSocketTest : public ::testing::Test {
uv_tcp_init(&loop, &client_socket);
uv_ip4_addr("127.0.0.1", PORT, &addr);
uv_tcp_bind(&server, reinterpret_cast<const struct sockaddr*>(&addr), 0);
int err = uv_listen(reinterpret_cast<uv_stream_t*>(&server),
1, on_new_connection);
GTEST_ASSERT_EQ(0, err);
GTEST_ASSERT_EQ(0, uv_listen(reinterpret_cast<uv_stream_t*>(&server),
1, on_new_connection));
uv_connect_t connect;
connect.data = nullptr;
uv_tcp_connect(&connect, &client_socket,
reinterpret_cast<const sockaddr*>(&addr), on_connection);
GTEST_ASSERT_EQ(0, uv_tcp_connect(&connect, &client_socket,
reinterpret_cast<const sockaddr*>(&addr),
on_connection));
uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
SPIN_WHILE(!connect.data || !connected);
really_close(reinterpret_cast<uv_handle_t*>(&server));
Expand Down
4 changes: 3 additions & 1 deletion test/cctest/test_inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class TestInspectorServerDelegate : public SocketServerDelegate {
public:
TestInspectorServerDelegate() : connected(0), disconnected(0),
targets_({ MAIN_TARGET_ID,
UNCONNECTABLE_TARGET_ID }) {}
UNCONNECTABLE_TARGET_ID }),
session_id_(0) {}

void Connect(InspectorSocketServer* server) {
server_ = server;
Expand Down Expand Up @@ -152,6 +153,7 @@ class SocketWrapper {
explicit SocketWrapper(uv_loop_t* loop) : closed_(false),
eof_(false),
loop_(loop),
socket_(uv_tcp_t()),
connected_(false),
sending_(false) { }

Expand Down

0 comments on commit 4bed947

Please sign in to comment.