Skip to content

Commit

Permalink
Fixing client reaping memory leak and error
Browse files Browse the repository at this point in the history
  • Loading branch information
grf14003 committed Mar 12, 2020
1 parent 65f4e5e commit 36f9d80
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bfs/include/DataSyncThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DataSyncThread
// if this one is still running
bool threadRunning = false;

std::vector<Attribute> incomingAttributes;
vector<Attribute> incomingAttributes;
HANDLE attribMutex;
public:
DataSyncThread(SOCKET s)
Expand Down
105 changes: 105 additions & 0 deletions bfs/scripts/log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,108 @@ Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
Hello new client!
Listening for clients...
18 changes: 10 additions & 8 deletions bfs/src/comms/AlgorithmServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ void AlgorithmServer::serverThreadRuntime()
while (continueThread)
{
write_log("Listening for clients...\n", 1, logger->filename, logger);
printf("Listening for clients...\n");
fprintf(stderr, "Listening for clients...\n");
ClientSocket = accept(ListenSocket, NULL, NULL);
write_log("Hello new client!\n", 1, logger->filename, logger);
printf("Hello new client!\n");
fprintf(stderr, "Hello new client!\n");
if (ClientSocket == INVALID_SOCKET) {
write_log("accept failed with error: ", 1, logger->filename, logger);
write_log(std::to_string(WSAGetLastError()), 1, logger->filename, logger);
Expand All @@ -100,15 +100,17 @@ void AlgorithmServer::serverThreadRuntime()
// Reaping any old data sync threads
if (lockClientThreadsMutex() == STATUS_WAIT_0)
{
auto it = clientThreads.begin();
while (clientThreads.size() > 0 && it != clientThreads.end())
for (vector<DataSyncThread*>::iterator x = clientThreads.begin(); x != clientThreads.end();)
{
if (!(**it).isClientConnected())
//Check for projectiles whos status is dead.
if (!(*x)->isRunning())
{
clientThreads.erase(it);
delete (*x);
x = clientThreads.erase(x);
}
else {
++it;
else
{
++x;
}
}

Expand Down

0 comments on commit 36f9d80

Please sign in to comment.