mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-18 23:42:26 +00:00
Fix new[]/delete missmatches and memory leaks found by clang's ASAN
Sometimes memory was allocated with new[] but freed with delete instead of delete[], which is wrong. And there were some small memory leaks, too. Furtunately clang's AddressSanitizer detected all that so I could easily fix it. (There seem to be some more small memory leaks which are harder to fix, though)
This commit is contained in:
parent
9950a5721f
commit
befe732dbb
7 changed files with 17 additions and 11 deletions
|
@ -861,20 +861,20 @@ idPVS::Shutdown
|
|||
*/
|
||||
void idPVS::Shutdown( void ) {
|
||||
if ( connectedAreas ) {
|
||||
delete connectedAreas;
|
||||
delete[] connectedAreas;
|
||||
connectedAreas = NULL;
|
||||
}
|
||||
if ( areaQueue ) {
|
||||
delete areaQueue;
|
||||
delete[] areaQueue;
|
||||
areaQueue = NULL;
|
||||
}
|
||||
if ( areaPVS ) {
|
||||
delete areaPVS;
|
||||
delete[] areaPVS;
|
||||
areaPVS = NULL;
|
||||
}
|
||||
if ( currentPVS ) {
|
||||
for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) {
|
||||
delete currentPVS[i].pvs;
|
||||
delete[] currentPVS[i].pvs;
|
||||
currentPVS[i].pvs = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1344,7 +1344,7 @@ pack_t *idFileSystemLocal::LoadZipFile( const char *zipfile ) {
|
|||
unzClose(uf);
|
||||
delete[] buildBuffer;
|
||||
delete pack;
|
||||
|
||||
Mem_Free( fs_headerLongs );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -861,20 +861,20 @@ idPVS::Shutdown
|
|||
*/
|
||||
void idPVS::Shutdown( void ) {
|
||||
if ( connectedAreas ) {
|
||||
delete connectedAreas;
|
||||
delete[] connectedAreas;
|
||||
connectedAreas = NULL;
|
||||
}
|
||||
if ( areaQueue ) {
|
||||
delete areaQueue;
|
||||
delete[] areaQueue;
|
||||
areaQueue = NULL;
|
||||
}
|
||||
if ( areaPVS ) {
|
||||
delete areaPVS;
|
||||
delete[] areaPVS;
|
||||
areaPVS = NULL;
|
||||
}
|
||||
if ( currentPVS ) {
|
||||
for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) {
|
||||
delete currentPVS[i].pvs;
|
||||
delete[] currentPVS[i].pvs;
|
||||
currentPVS[i].pvs = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,11 @@ public:
|
|||
explicit idPolynomial( float a, float b, float c, float d );
|
||||
explicit idPolynomial( float a, float b, float c, float d, float e );
|
||||
|
||||
~idPolynomial() // DG: don't leak coefficient's memory!
|
||||
{
|
||||
Mem_Free16( coefficient );
|
||||
}
|
||||
|
||||
float operator[]( int index ) const;
|
||||
float & operator[]( int index );
|
||||
|
||||
|
|
|
@ -318,6 +318,7 @@ void Sys_InitNetworking(void)
|
|||
if (num_interfaces >= MAX_INTERFACES)
|
||||
break;
|
||||
}
|
||||
freeifaddrs(ifap);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -42,7 +42,7 @@ idWinVar::idWinVar() {
|
|||
}
|
||||
|
||||
idWinVar::~idWinVar() {
|
||||
delete name;
|
||||
delete[] name;
|
||||
name = NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ public:
|
|||
return "";
|
||||
}
|
||||
void SetName(const char *_name) {
|
||||
delete []name;
|
||||
delete[] name;
|
||||
name = NULL;
|
||||
if (_name) {
|
||||
name = new char[strlen(_name)+1];
|
||||
|
|
Loading…
Reference in a new issue