Unverified Commit 5a417414 authored by Songqing Zhang's avatar Songqing Zhang Committed by GitHub
Browse files

[Bug] fix memory leak in cpp tests (#6141)

parent 97c3f870
......@@ -128,6 +128,8 @@ WorkspacePool::~WorkspacePool() {
* Comment out the destruct of WorkspacePool, due to Segmentation fault with
* MXNet Since this will be only called at the termination of process, not
* manually wiping out should not cause problems.
* Note, this will cause memory leak without the following code, so, maybe
* we need to solve the problem.
*/
// for (size_t i = 0; i < array_.size(); ++i) {
// if (array_[i] != nullptr) {
......
......@@ -89,9 +89,9 @@ TEST(MessageQueueTest, MultiThread) {
MessageQueue queue(100000, kNumOfProducer);
EXPECT_EQ(queue.EmptyAndNoMoreAdd(), false);
EXPECT_EQ(queue.Empty(), true);
std::vector<std::thread*> thread_pool;
std::vector<std::thread> thread_pool(kNumOfProducer);
for (int i = 0; i < kNumOfProducer; ++i) {
thread_pool.push_back(new std::thread(start_add, &queue, i));
thread_pool[i] = std::thread(start_add, &queue, i);
}
for (int i = 0; i < kNumOfProducer * kNumOfMessage; ++i) {
Message msg;
......@@ -99,7 +99,7 @@ TEST(MessageQueueTest, MultiThread) {
EXPECT_EQ(string(msg.data, msg.size), string("apple"));
}
for (int i = 0; i < kNumOfProducer; ++i) {
thread_pool[i]->join();
thread_pool[i].join();
}
EXPECT_EQ(queue.EmptyAndNoMoreAdd(), true);
}
......@@ -44,20 +44,20 @@ static void start_server(int id);
TEST(SocketCommunicatorTest, SendAndRecv) {
// start 10 client
std::vector<std::thread*> client_thread;
std::vector<std::thread> client_thread(kNumSender);
for (int i = 0; i < kNumSender; ++i) {
client_thread.push_back(new std::thread(start_client));
client_thread[i] = std::thread(start_client);
}
// start 10 server
std::vector<std::thread*> server_thread;
std::vector<std::thread> server_thread(kNumReceiver);
for (int i = 0; i < kNumReceiver; ++i) {
server_thread.push_back(new std::thread(start_server, i));
server_thread[i] = std::thread(start_server, i);
}
for (int i = 0; i < kNumSender; ++i) {
client_thread[i]->join();
client_thread[i].join();
}
for (int i = 0; i < kNumReceiver; ++i) {
server_thread[i]->join();
server_thread[i].join();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment