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:
Daniel Gibson 2015-12-17 18:11:03 +01:00
parent 9950a5721f
commit befe732dbb
7 changed files with 17 additions and 11 deletions

View file

@ -861,20 +861,20 @@ idPVS::Shutdown
*/ */
void idPVS::Shutdown( void ) { void idPVS::Shutdown( void ) {
if ( connectedAreas ) { if ( connectedAreas ) {
delete connectedAreas; delete[] connectedAreas;
connectedAreas = NULL; connectedAreas = NULL;
} }
if ( areaQueue ) { if ( areaQueue ) {
delete areaQueue; delete[] areaQueue;
areaQueue = NULL; areaQueue = NULL;
} }
if ( areaPVS ) { if ( areaPVS ) {
delete areaPVS; delete[] areaPVS;
areaPVS = NULL; areaPVS = NULL;
} }
if ( currentPVS ) { if ( currentPVS ) {
for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) { for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) {
delete currentPVS[i].pvs; delete[] currentPVS[i].pvs;
currentPVS[i].pvs = NULL; currentPVS[i].pvs = NULL;
} }
} }

View file

@ -1344,7 +1344,7 @@ pack_t *idFileSystemLocal::LoadZipFile( const char *zipfile ) {
unzClose(uf); unzClose(uf);
delete[] buildBuffer; delete[] buildBuffer;
delete pack; delete pack;
Mem_Free( fs_headerLongs );
return NULL; return NULL;
} }
} }

View file

@ -861,20 +861,20 @@ idPVS::Shutdown
*/ */
void idPVS::Shutdown( void ) { void idPVS::Shutdown( void ) {
if ( connectedAreas ) { if ( connectedAreas ) {
delete connectedAreas; delete[] connectedAreas;
connectedAreas = NULL; connectedAreas = NULL;
} }
if ( areaQueue ) { if ( areaQueue ) {
delete areaQueue; delete[] areaQueue;
areaQueue = NULL; areaQueue = NULL;
} }
if ( areaPVS ) { if ( areaPVS ) {
delete areaPVS; delete[] areaPVS;
areaPVS = NULL; areaPVS = NULL;
} }
if ( currentPVS ) { if ( currentPVS ) {
for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) { for ( int i = 0; i < MAX_CURRENT_PVS; i++ ) {
delete currentPVS[i].pvs; delete[] currentPVS[i].pvs;
currentPVS[i].pvs = NULL; currentPVS[i].pvs = NULL;
} }
} }

View file

@ -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 );
explicit idPolynomial( float a, float b, float c, float d, float e ); 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 ) const;
float & operator[]( int index ); float & operator[]( int index );

View file

@ -318,6 +318,7 @@ void Sys_InitNetworking(void)
if (num_interfaces >= MAX_INTERFACES) if (num_interfaces >= MAX_INTERFACES)
break; break;
} }
freeifaddrs(ifap);
} }
/* /*

View file

@ -42,7 +42,7 @@ idWinVar::idWinVar() {
} }
idWinVar::~idWinVar() { idWinVar::~idWinVar() {
delete name; delete[] name;
name = NULL; name = NULL;
} }

View file

@ -51,7 +51,7 @@ public:
return ""; return "";
} }
void SetName(const char *_name) { void SetName(const char *_name) {
delete []name; delete[] name;
name = NULL; name = NULL;
if (_name) { if (_name) {
name = new char[strlen(_name)+1]; name = new char[strlen(_name)+1];