Skip to content
Snippets Groups Projects
Commit 59e42518 authored by Carsten Patzke's avatar Carsten Patzke
Browse files

Fixed memory leak

parent 5c0cd7ab
No related branches found
No related tags found
No related merge requests found
......@@ -70,7 +70,7 @@ class IO {
/*
* Special
*/
virtual std::thread* NewThread (std::function<void()> function) const = 0;
virtual std::unique_ptr<std::thread> NewThread (std::function<void()> function) const = 0;
/*
* Network
......
......@@ -51,7 +51,7 @@ class SystemIO final : public IO {
/*
* Special
*/
std::thread* NewThread(std::function<void()> function) const;
std::unique_ptr<std::thread> NewThread(std::function<void()> function) const;
// this is not standard function - to be implemented differently in windows and linux
......
......@@ -8,7 +8,10 @@
namespace hidra2 {
class MockIO : public IO {
public:
MOCK_CONST_METHOD1(NewThread, std::thread * (std::function<void()> function));
std::unique_ptr<std::thread> NewThread(std::function<void()> function) const override {
return std::unique_ptr<std::thread>(NewThread_t(function));
}
MOCK_CONST_METHOD1(NewThread_t, std::thread * (std::function<void()> function));
SocketDescriptor CreateSocket(AddressFamilies address_family, SocketTypes socket_type, SocketProtocols socket_protocol,
Error* err) const override {
......
......@@ -131,8 +131,8 @@ std::string SystemIO::ReadFileToString(const std::string& fname, Error* err) con
}
std::thread* SystemIO::NewThread(std::function<void()> function) const {
return new std::thread(function);
std::unique_ptr<std::thread> SystemIO::NewThread(std::function<void()> function) const {
return std::unique_ptr<std::thread>(new std::thread(function));
}
void SystemIO::Skip(SocketDescriptor socket_fd, size_t length, Error* err) const {
......
......@@ -135,7 +135,7 @@ FileInfo SystemIO::GetFileInfo(const std::string& name, Error* err) const {
}
void ProcessFileEntity(const WIN32_FIND_DATA& f, const std::string& path,
FileInfos* files, Error* err) {
FileInfos* files, Error* err) {
*err = nullptr;
if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
......
......@@ -82,7 +82,6 @@ void NetworkProducerPeer::stop_peer_listener() {
if(!listener_thread_)
return;
listener_thread_->join();
delete listener_thread_;
listener_thread_ = nullptr;
}
......
......@@ -29,11 +29,11 @@ class NetworkProducerPeer : HasIO {
static const std::vector<RequestHandlerInformation> kRequestHandlers;
static std::atomic<uint32_t> kNetworkProducerPeerCount;
uint32_t connection_id_;
int socket_fd_;
uint32_t connection_id_;
int socket_fd_;
bool is_listening_ = false;
std::thread* listener_thread_ = nullptr;
bool is_listening_ = false;
std::unique_ptr<std::thread> listener_thread_ = nullptr;
void internal_receiver_thread_();
size_t handle_generic_request_(GenericNetworkRequest* request, GenericNetworkResponse* response);
......
......@@ -20,7 +20,7 @@ class Receiver : public HasIO {
private:
bool listener_running_ = false;
FileDescriptor listener_fd_ = -1;
std::thread* accept_thread_ = nullptr;
std::unique_ptr<std::thread> accept_thread_ = nullptr;
void AcceptThreadLogic();
std::list<std::unique_ptr<NetworkProducerPeer>> peer_list_;
......
......@@ -35,7 +35,7 @@ void ExitIfErrIsNotOk(Error* err, int exit_number) {
}
}
std::thread* CreateEchoServerThread() {
std::unique_ptr<std::thread> CreateEchoServerThread() {
return io->NewThread([&] {
Error err;
FileDescriptor socket = io->CreateSocket(AddressFamilies::INET, SocketTypes::STREAM, SocketProtocols::IP, &err);
......@@ -163,7 +163,7 @@ int main(int argc, char* argv[]) {
ExitIfErrIsNotOk(&err, 303);
}
std::thread* server_thread = CreateEchoServerThread();
std::unique_ptr<std::thread> server_thread = CreateEchoServerThread();
kThreadStarted.get_future().get();//Make sure that the server is started
std::cout << "Check 1" << std::endl;
......
......@@ -36,7 +36,7 @@ void ExitIfErrIsNotOk(Error* err, int exit_number) {
}
}
std::thread* CreateEchoServerThread() {
std::unique_ptr<std::thread> CreateEchoServerThread() {
return io->NewThread([] {
std::unique_ptr<uint8_t[]> kBufferServer(new uint8_t[kTestSize]);
......@@ -104,7 +104,7 @@ void Speedtest() {
}
int main(int argc, char* argv[]) {
std::thread* server_thread = CreateEchoServerThread();
std::unique_ptr<std::thread> server_thread = CreateEchoServerThread();
kThreadStarted.get_future().get();//Make sure that the server is started
Speedtest();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment