Memory Leak Fixes

From Valve Developer Community
Revision as of 19:17, 25 March 2006 by Ts2do (talk | contribs)
Jump to navigation Jump to search

On this page goes fixes for memory leaks in the SDK.

Shared

KeyValues class

See KeyValues class

bin\client.dll

CPanelMetaClassMgrImp class

src\cl_dll\panelmetaclassmgr.cpp
236a237,242
 CPanelMetaClassMgrImp::~CPanelMetaClassMgrImp()
 {
>	while(m_MetaClassKeyValues.Count()>0)
>	{
>		if(m_MetaClassKeyValues[0])
>			m_MetaClassKeyValues[0]->deleteThis();
>		m_MetaClassKeyValues.RemoveAt(0);
>	}
 }

CSentence class

src\public\sentence.cpp
787c787
<	delete m_szText;
---
>	delete[] m_szText;

RecvTable class

Note.pngNote:I am not completely sure if this is a valid deletion... It seems right, can someone validate it by testing?
src\public\dt_recv.cpp
93a94
 RecvTable::~RecvTable()
 {
>	delete [] m_pProps;
 }

bin\server.dll

CActBusyAnimData class

src\dlls\hl2_dll\ai_behavior_actbusy.cpp
124a125
>       pKVAnimData->deleteThis();
137c138
<       pAnim->iszSequences[BA_BUSY] = pSequence ? pSequence : NULL_STRING;
---
>       pAnim->iszSequences[BA_BUSY] = pSequence ? AllocPooledString( pSequence ) : NULL_STRING;
139c140
<       pAnim->iszSequences[BA_ENTRY] = pSequence ? pSequence : NULL_STRING;
---
>       pAnim->iszSequences[BA_ENTRY] = pSequence ? AllocPooledString( pSequence ) : NULL_STRING;
141c142
<       pAnim->iszSequences[BA_EXIT] = pSequence ? pSequence : NULL_STRING;
---
>       pAnim->iszSequences[BA_EXIT] = pSequence ? AllocPooledString( pSequence ) : NULL_STRING;

WCEdit

src\dlls\wcedit.cpp
449a450,460
 Vector *g_EntityPositions = NULL;
 QAngle *g_EntityOrientations = NULL;
 string_t *g_EntityClassnames = NULL;

>class GlobalCleanUp : public CAutoGameSystem
>{
>	void Shutdown()
>	{
>		delete [] g_EntityPositions;
>		delete [] g_EntityOrientations;
>		delete [] g_EntityClassnames;
>		delete this;
>	}
>};
>

459a471
	if ( !g_EntityPositions )
	{
>		new GlobalCleanUp();
		g_EntityPositions = new Vector[NUM_ENT_ENTRIES];
		g_EntityOrientations = new QAngle[NUM_ENT_ENTRIES];
		// have to save these too because some entities change the classname on spawn (e.g. prop_physics_override, physics_prop)
		g_EntityClassnames = new string_t[NUM_ENT_ENTRIES];
	}

src\lib\vgui_controls.lib

» See Compiling vgui_controls.lib «

AnimationController class

src\vgui2\controls\AnimationController.cpp
1292a1293,1311
	~CPanelAnimationDictionary()
	{
>		int v2, v1 = m_AnimationMaps.Count();
>		PanelAnimationMapEntry *pCur;
>		PanelAnimationMap *pMap;
>		for(int x=0;x<v1;x++)
>		{
>			pMap = m_AnimationMaps[x].map;
>			if(pMap)
>			{
>				v2 = pMap->entries.Count();
>				for(int y=0;y<v2;y++)
>				{
>					pCur = &(pMap->entries[y]);
>					delete [] pCur->m_pszScriptName;
>					delete [] pCur->m_pszVariable;
>					delete [] pCur->m_pszType;
>					delete [] pCur->m_pszDefaultValue;
>				}
>			}
>		}
		m_PanelAnimationMapPool.Clear();
	}

CBitmapImagePanel class

src\public\vgui_controls\BitmapImagePanel.h
21a22
	CBitmapImagePanel( vgui::Panel *parent, char const *panelName, char const *filename = NULL );
>	~CBitmapImagePanel();
src\vgui2\controls\BitmapImagePanel.cpp
61a62,67
>CBitmapImagePanel::~CBitmapImagePanel()
>{
>	delete [] m_pszImageName;
>	delete [] m_pszColorName;
>}
>
 //-----------------------------------------------------------------------------
 // Purpose: 
 //-----------------------------------------------------------------------------
 void CBitmapImagePanel::ComputeImagePosition(int &x, int &y, int &w, int &h)

DirectorySelectDialog class

src\vgui2\controls\DirectorySelectDialog.cpp
258c258,260
<	int rootIndex = m_pDirTree->AddItem(new KeyValues("root", "Text", m_szCurrentDrive), -1);
---
>	KeyValues *kv = new KeyValues("root", "Text", m_szCurrentDrive);
>	int rootIndex = m_pDirTree->AddItem(kv, -1);
>	kv->deleteThis();
294a297
				m_pDirTree->AddItem(kv, parentNodeIndex);
>				kv->deleteThis();
			}
410a414
			int itemID = m_pDirTree->AddItem(kv, selectedIndex);
>			kv->deleteThis();

FileOpenDialog class

src\vgui2\controls\FileOpenDialog.cpp
506a507
	int itemID = m_pFileTypeCombo->AddItem(filterName, kv);
>	kv->deleteThis();
	if ( bActive )

ScrollBar class

src\vgui2\controls\ScrollBar.cpp
323c323
<               _button[index]->SetParent((Panel *)NULL);
---
>               _button[index]->DeletePanel();
351c351
<               _slider->SetParent((Panel *)NULL);
---
>               _slider->DeletePanel();

SectionedListPanel class

src\vgui2\controls\SectionedListPanel.cpp
1579a1580
		m_hEditModePanel->SetVisible(false);
		m_hEditModePanel->SetParent((Panel *)NULL);
>		delete m_hEditModePanel;
		m_hEditModePanel = NULL;