test: fix memory leaks in inspector tests · nodejs/node@0190db4
@@ -288,10 +288,10 @@ static bool waiting_to_close = true;
288288289289void handle_closed(uv_handle_t* handle) { waiting_to_close = false; }
290290291-static void really_close(uv_tcp_t* socket) {
291+static void really_close(uv_handle_t* handle) {
292292 waiting_to_close = true;
293-if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(socket))) {
294-uv_close(reinterpret_cast<uv_handle_t*>(socket), handle_closed);
293+if (!uv_is_closing(handle)) {
294+uv_close(handle, handle_closed);
295295SPIN_WHILE(waiting_to_close);
296296 }
297297}
@@ -300,6 +300,7 @@ static void really_close(uv_tcp_t* socket) {
300300static void manual_inspector_socket_cleanup() {
301301EXPECT_EQ(0, uv_is_active(
302302reinterpret_cast<uv_handle_t*>(&inspector.client)));
303+really_close(reinterpret_cast<uv_handle_t*>(&inspector.client));
303304free(inspector.ws_state);
304305free(inspector.http_parsing_state);
305306free(inspector.buffer);
@@ -339,21 +340,13 @@ class InspectorSocketTest : public ::testing::Test {
339340reinterpret_cast<const sockaddr *>(&addr), on_connection);
340341uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
341342SPIN_WHILE(!connect.data || !connected);
342-really_close(&server);
343-uv_unref(reinterpret_cast<uv_handle_t*>(&server));
343+really_close(reinterpret_cast<uv_handle_t*>(&server));
344344 }
345345346346virtual void TearDown() {
347-really_close(&client_socket);
348-for (int i = 0; i < MAX_LOOP_ITERATIONS; i++)
349-uv_run(&loop, UV_RUN_NOWAIT);
347+really_close(reinterpret_cast<uv_handle_t*>(&client_socket));
348+really_close(reinterpret_cast<uv_handle_t*>(&timeout_timer));
350349EXPECT_EQ(nullptr, inspector.buffer);
351-uv_stop(&loop);
352-int err = uv_run(&loop, UV_RUN_ONCE);
353-if (err != 0) {
354-uv_print_active_handles(&loop, stderr);
355- }
356-EXPECT_EQ(0, err);
357350 expectations* expects = static_cast<expectations*>(inspector.data);
358351if (expects != nullptr) {
359352GTEST_ASSERT_EQ(expects->actual_end, expects->actual_offset);
@@ -362,7 +355,11 @@ class InspectorSocketTest : public ::testing::Test {
362355free(expects);
363356 inspector.data = nullptr;
364357 }
365-uv_loop_close(&loop);
358+const int err = uv_loop_close(&loop);
359+if (err != 0) {
360+uv_print_all_handles(&loop, stderr);
361+ }
362+EXPECT_EQ(0, err);
366363 }
367364};
368365