1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-17 20:58:07 +02:00

Fixed few more memory leaks in client

This commit is contained in:
Ivan Savenko 2023-11-13 13:43:46 +02:00
parent 20ef3a69e7
commit a6f37b7cd7
6 changed files with 11 additions and 12 deletions

View File

@ -481,6 +481,7 @@ static void quitApplication()
vstd::clear_pointer(graphics);
}
vstd::clear_pointer(CSH);
vstd::clear_pointer(VLC);
vstd::clear_pointer(console);// should be removed after everything else since used by logging

View File

@ -20,7 +20,9 @@ class ICPackVisitor;
struct DLL_LINKAGE CPack
{
std::shared_ptr<CConnection> c; // Pointer to connection that pack received from
/// Pointer to connection that pack received from
/// Only set & used on server
std::shared_ptr<CConnection> c;
CPack() = default;
virtual ~CPack() = default;

View File

@ -23,4 +23,9 @@ BinaryDeserializer::BinaryDeserializer(IBinaryReader * r): CLoaderBase(r)
registerTypes(*this);
}
BinaryDeserializer::~BinaryDeserializer()
{
}
VCMI_LIB_NAMESPACE_END

View File

@ -140,12 +140,12 @@ public:
si32 fileVersion;
std::map<ui32, void*> loadedPointers;
std::map<ui32, const std::type_info*> loadedPointersTypes;
std::map<const void*, std::shared_ptr<void>> loadedSharedPointers;
bool smartPointerSerialization;
bool saving;
BinaryDeserializer(IBinaryReader * r);
~BinaryDeserializer();
template<class T>
BinaryDeserializer & operator&(T & t)
@ -279,7 +279,6 @@ public:
{
// We already got this pointer
// Cast it in case we are loading it to a non-first base pointer
assert(loadedPointersTypes.count(pid));
data = static_cast<T>(i->second);
return;
}
@ -313,10 +312,7 @@ public:
void ptrAllocated(const T *ptr, ui32 pid)
{
if(smartPointerSerialization && pid != 0xffffffff)
{
loadedPointersTypes[pid] = &typeid(T);
loadedPointers[pid] = (void*)ptr; //add loaded pointer to our lookup map; cast is to avoid errors with const T* pt
}
}
template<typename Base, typename Derived> void registerType(const Base * b = nullptr, const Derived * d = nullptr)

View File

@ -269,13 +269,7 @@ CPack * CConnection::retrievePack()
iser & pack;
logNetwork->trace("Received CPack of type %s", (pack ? typeid(*pack).name() : "nullptr"));
if(pack == nullptr)
{
logNetwork->error("Received a nullptr CPack! You should check whether client and server ABI matches.");
}
else
{
pack->c = this->shared_from_this();
}
enableBufferedRead = false;

View File

@ -445,6 +445,7 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c)
try
{
pack = c->retrievePack();
pack->c = c;
}
catch(boost::system::system_error & e)
{