소스 검색

Fixed few more memory leaks in client

Ivan Savenko 2 년 전
부모
커밋
a6f37b7cd7
6개의 변경된 파일11개의 추가작업 그리고 12개의 파일을 삭제
  1. 1 0
      client/CMT.cpp
  2. 3 1
      lib/networkPacks/NetPacksBase.h
  3. 5 0
      lib/serializer/BinaryDeserializer.cpp
  4. 1 5
      lib/serializer/BinaryDeserializer.h
  5. 0 6
      lib/serializer/Connection.cpp
  6. 1 0
      server/CVCMIServer.cpp

+ 1 - 0
client/CMT.cpp

@@ -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

+ 3 - 1
lib/networkPacks/NetPacksBase.h

@@ -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;

+ 5 - 0
lib/serializer/BinaryDeserializer.cpp

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

+ 1 - 5
lib/serializer/BinaryDeserializer.h

@@ -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)

+ 0 - 6
lib/serializer/Connection.cpp

@@ -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;
 

+ 1 - 0
server/CVCMIServer.cpp

@@ -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)
 		{