Fix memory leaks and errors

This commit is contained in:
momo5502 2016-06-30 19:38:48 +02:00
parent 9451964046
commit e08f1f1ba9
16 changed files with 62 additions and 28 deletions

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit a478dc59354deb19d01a9e9138bcfac76a0347e3 Subproject commit 421b420a0c159a8cbd027f87674b19f4a9b77993

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit e0016c5b6ae61ad60d260a78c5834cc537b46d10 Subproject commit c18aa7795a2e02ef700ff8b039d94ecdcc33432f

View File

@ -28,16 +28,18 @@ namespace Components
STATE_INVALID, STATE_INVALID,
}; };
struct AuthInfo class AuthInfo
{ {
public:
Utils::Cryptography::ECC::Key publicKey; Utils::Cryptography::ECC::Key publicKey;
std::string challenge; std::string challenge;
AuthState state; AuthState state;
int time; int time;
}; };
struct TokenIncrementing class TokenIncrementing
{ {
public:
bool cancel; bool cancel;
bool generating; bool generating;
std::thread thread; std::thread thread;

View File

@ -10,8 +10,9 @@ namespace Components
static bool Used(); static bool Used();
private: private:
struct Container class Container
{ {
public:
bool Evaluated; bool Evaluated;
bool Invoked; bool Invoked;
std::string ConnectString; std::string ConnectString;

View File

@ -10,8 +10,9 @@ namespace Components
static void Perform(); static void Perform();
private: private:
struct Container class Container
{ {
public:
bool Perform; bool Perform;
bool Terminate; bool Terminate;
std::thread Thread; std::thread Thread;

View File

@ -5,8 +5,9 @@ namespace Components
public: public:
typedef void(Callback)(); typedef void(Callback)();
struct Flag class Flag
{ {
public:
Flag(Game::dvar_flag flag) : val(flag){}; Flag(Game::dvar_flag flag) : val(flag){};
Flag(int flag) : Flag((Game::dvar_flag)flag) {}; Flag(int flag) : Flag((Game::dvar_flag)flag) {};

View File

@ -403,13 +403,16 @@ namespace Components
void Menus::RemoveMenu(Game::menuDef_t* menudef) void Menus::RemoveMenu(Game::menuDef_t* menudef)
{ {
for (auto i = Menus::MenuList.begin(); i != Menus::MenuList.end(); ++i) for (auto i = Menus::MenuList.begin(); i != Menus::MenuList.end();)
{ {
if (i->second == menudef) if (i->second == menudef)
{ {
Menus::FreeMenu(menudef); Menus::FreeMenu(menudef);
i = Menus::MenuList.erase(i); i = Menus::MenuList.erase(i);
break; }
else
{
++i;
} }
} }
} }

View File

@ -166,12 +166,16 @@ namespace Components
void Node::DeleteInvalidSessions() void Node::DeleteInvalidSessions()
{ {
for (auto i = Node::Sessions.begin(); i != Node::Sessions.end(); ++i) for (auto i = Node::Sessions.begin(); i != Node::Sessions.end();)
{ {
if (i->lastTime <= 0 || (Game::Sys_Milliseconds() - i->lastTime) > SESSION_TIMEOUT) if (i->lastTime <= 0 || (Game::Sys_Milliseconds() - i->lastTime) > SESSION_TIMEOUT)
{ {
i = Node::Sessions.erase(i); i = Node::Sessions.erase(i);
} }
else
{
++i;
}
} }
} }

View File

@ -33,8 +33,9 @@ namespace Components
STATE_INVALID, STATE_INVALID,
}; };
struct NodeEntry class NodeEntry
{ {
public:
Network::Address address; Network::Address address;
std::string challenge; std::string challenge;
Utils::Cryptography::ECC::Key publicKey; Utils::Cryptography::ECC::Key publicKey;
@ -52,8 +53,9 @@ namespace Components
uint32_t version; uint32_t version;
}; };
struct ClientSession class ClientSession
{ {
public:
Network::Address address; Network::Address address;
std::string challenge; std::string challenge;
bool valid; bool valid;

View File

@ -17,8 +17,9 @@ namespace Components
static void PlaylistError(std::string error); static void PlaylistError(std::string error);
private: private:
struct JoinContainer class JoinContainer
{ {
public:
Network::Address Target; Network::Address Target;
std::string Challenge; std::string Challenge;
DWORD JoinTime; DWORD JoinTime;

View File

@ -8,8 +8,9 @@ namespace Components
const char* GetName() { return "RCon"; }; const char* GetName() { return "RCon"; };
private: private:
struct Container class Container
{ {
public:
int timestamp; int timestamp;
std::string output; std::string output;
std::string challenge; std::string challenge;

View File

@ -10,10 +10,12 @@ namespace Components
static Utils::InfoString GetInfo(); static Utils::InfoString GetInfo();
private: private:
struct Container class Container
{ {
struct Player public:
class Player
{ {
public:
int Ping; int Ping;
int Score; int Score;
std::string Name; std::string Name;

View File

@ -376,7 +376,7 @@ namespace Components
{ {
ServerList::RefreshContainer.Mutex.lock(); ServerList::RefreshContainer.Mutex.lock();
for (auto i = ServerList::RefreshContainer.Servers.begin(); i != ServerList::RefreshContainer.Servers.end(); ++i) for (auto i = ServerList::RefreshContainer.Servers.begin(); i != ServerList::RefreshContainer.Servers.end();)
{ {
// Our desired server // Our desired server
if (i->Target == address && i->Sent) if (i->Target == address && i->Sent)
@ -412,22 +412,28 @@ namespace Components
if (!list) return; if (!list) return;
unsigned int k = 0; unsigned int k = 0;
for (auto j = list->begin(); j != list->end(); ++j, ++k) for (auto j = list->begin(); j != list->end(); ++k)
{ {
if (j->Addr == address) if (j->Addr == address)
{ {
j = list->erase(j); j = list->erase(j);
break; }
else
{
++j;
} }
} }
// Also remove from visible list // Also remove from visible list
for (auto j = ServerList::VisibleList.begin(); j != ServerList::VisibleList.end(); ++j) for (auto j = ServerList::VisibleList.begin(); j != ServerList::VisibleList.end();)
{ {
if (*j == k) if (*j == k)
{ {
j = ServerList::VisibleList.erase(j); j = ServerList::VisibleList.erase(j);
break; }
else
{
++j;
} }
} }
@ -449,6 +455,10 @@ namespace Components
break; break;
} }
else
{
++i;
}
} }
ServerList::RefreshContainer.Mutex.unlock(); ServerList::RefreshContainer.Mutex.unlock();

View File

@ -5,8 +5,9 @@ namespace Components
public: public:
typedef int(SortCallback)(const void*, const void*); typedef int(SortCallback)(const void*, const void*);
struct ServerInfo class ServerInfo
{ {
public:
Network::Address Addr; Network::Address Addr;
std::string Hostname; std::string Hostname;
std::string Mapname; std::string Mapname;
@ -73,10 +74,12 @@ namespace Components
}; };
#pragma pack(pop) #pragma pack(pop)
struct Container class Container
{ {
struct ServerContainer public:
class ServerContainer
{ {
public:
bool Sent; bool Sent;
int SendTime; int SendTime;
std::string Challenge; std::string Challenge;

View File

@ -7,10 +7,12 @@ namespace Components
const char* GetName() { return "Theatre"; }; const char* GetName() { return "Theatre"; };
private: private:
struct Container class Container
{ {
struct DemoInfo public:
class DemoInfo
{ {
public:
std::string Name; std::string Name;
std::string Mapname; std::string Mapname;
std::string Gametype; std::string Gametype;

View File

@ -10,8 +10,9 @@ namespace Components
static void Show(const char* image, const char* title, const char* description, int length); static void Show(const char* image, const char* title, const char* description, int length);
private: private:
struct UIToast class UIToast
{ {
public:
std::string Image; std::string Image;
std::string Title; std::string Title;
std::string Desc; std::string Desc;