Переглянути джерело

Remove old data structure from struct_data map, prevents memory leak / buffer overflow

Fix #182 may also be the reason for Fix #180
image 4 роки тому
батько
коміт
0341a2f210
1 змінених файлів з 9 додано та 0 видалено
  1. 9 0
      EQ2/source/common/PacketStruct.cpp

+ 9 - 0
EQ2/source/common/PacketStruct.cpp

@@ -450,11 +450,20 @@ PacketStruct::~PacketStruct() {
 }
 
 void PacketStruct::deleteDataStructs(vector<DataStruct*>* data_structs) {
+	if ( !data_structs || data_structs->size() == 0 )
+	return;
+
 	DataStruct* data = 0;
 	vector<DataStruct*>::iterator itr;
 	for (itr = data_structs->begin(); itr != data_structs->end(); itr++) {
 		data = *itr;
 		void* ptr = GetStructPointer(data);
+
+		// stop the struct_data from growing with old data/ptr info, memory leaking and eventual buffer overflow (crash)
+		map<DataStruct*, void*>::iterator datastr = struct_data.find(data);
+		if (datastr != struct_data.end())
+			struct_data.erase(datastr);
+
 		switch (data->GetType()) {
 		case DATA_STRUCT_EQ2_8BIT_STRING: {
 			EQ2_8BitString* real_ptr = (EQ2_8BitString*)ptr;