mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-19 00:17:56 +02:00
Fixed few more memory leaks in client
This commit is contained in:
@ -481,6 +481,7 @@ static void quitApplication()
|
|||||||
vstd::clear_pointer(graphics);
|
vstd::clear_pointer(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vstd::clear_pointer(CSH);
|
||||||
vstd::clear_pointer(VLC);
|
vstd::clear_pointer(VLC);
|
||||||
|
|
||||||
vstd::clear_pointer(console);// should be removed after everything else since used by logging
|
vstd::clear_pointer(console);// should be removed after everything else since used by logging
|
||||||
|
@ -20,7 +20,9 @@ class ICPackVisitor;
|
|||||||
|
|
||||||
struct DLL_LINKAGE CPack
|
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;
|
CPack() = default;
|
||||||
virtual ~CPack() = default;
|
virtual ~CPack() = default;
|
||||||
|
@ -23,4 +23,9 @@ BinaryDeserializer::BinaryDeserializer(IBinaryReader * r): CLoaderBase(r)
|
|||||||
registerTypes(*this);
|
registerTypes(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BinaryDeserializer::~BinaryDeserializer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@ -140,12 +140,12 @@ public:
|
|||||||
si32 fileVersion;
|
si32 fileVersion;
|
||||||
|
|
||||||
std::map<ui32, void*> loadedPointers;
|
std::map<ui32, void*> loadedPointers;
|
||||||
std::map<ui32, const std::type_info*> loadedPointersTypes;
|
|
||||||
std::map<const void*, std::shared_ptr<void>> loadedSharedPointers;
|
std::map<const void*, std::shared_ptr<void>> loadedSharedPointers;
|
||||||
bool smartPointerSerialization;
|
bool smartPointerSerialization;
|
||||||
bool saving;
|
bool saving;
|
||||||
|
|
||||||
BinaryDeserializer(IBinaryReader * r);
|
BinaryDeserializer(IBinaryReader * r);
|
||||||
|
~BinaryDeserializer();
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
BinaryDeserializer & operator&(T & t)
|
BinaryDeserializer & operator&(T & t)
|
||||||
@ -279,7 +279,6 @@ public:
|
|||||||
{
|
{
|
||||||
// We already got this pointer
|
// We already got this pointer
|
||||||
// Cast it in case we are loading it to a non-first base 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);
|
data = static_cast<T>(i->second);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -313,10 +312,7 @@ public:
|
|||||||
void ptrAllocated(const T *ptr, ui32 pid)
|
void ptrAllocated(const T *ptr, ui32 pid)
|
||||||
{
|
{
|
||||||
if(smartPointerSerialization && pid != 0xffffffff)
|
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
|
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)
|
template<typename Base, typename Derived> void registerType(const Base * b = nullptr, const Derived * d = nullptr)
|
||||||
|
@ -269,13 +269,7 @@ CPack * CConnection::retrievePack()
|
|||||||
iser & pack;
|
iser & pack;
|
||||||
logNetwork->trace("Received CPack of type %s", (pack ? typeid(*pack).name() : "nullptr"));
|
logNetwork->trace("Received CPack of type %s", (pack ? typeid(*pack).name() : "nullptr"));
|
||||||
if(pack == nullptr)
|
if(pack == nullptr)
|
||||||
{
|
|
||||||
logNetwork->error("Received a nullptr CPack! You should check whether client and server ABI matches.");
|
logNetwork->error("Received a nullptr CPack! You should check whether client and server ABI matches.");
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pack->c = this->shared_from_this();
|
|
||||||
}
|
|
||||||
|
|
||||||
enableBufferedRead = false;
|
enableBufferedRead = false;
|
||||||
|
|
||||||
|
@ -445,6 +445,7 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
pack = c->retrievePack();
|
pack = c->retrievePack();
|
||||||
|
pack->c = c;
|
||||||
}
|
}
|
||||||
catch(boost::system::system_error & e)
|
catch(boost::system::system_error & e)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user