don't check for NULL, while doing free()

This commit is contained in:
Garux 2020-01-20 19:14:52 +03:00
parent 67820df935
commit dfae69d446
10 changed files with 29 additions and 87 deletions

View File

@ -86,9 +86,7 @@ int numFogs;
dfog_t dfogs[MAX_MAP_FOGS]; dfog_t dfogs[MAX_MAP_FOGS];
void SetLightBytes( int n ){ void SetLightBytes( int n ){
if ( lightBytes != 0 ) {
free( lightBytes ); free( lightBytes );
}
numLightBytes = n; numLightBytes = n;
@ -100,9 +98,7 @@ void SetLightBytes( int n ){
} }
void SetGridPoints( int n ){ void SetGridPoints( int n ){
if ( gridData != 0 ) {
free( gridData ); free( gridData );
}
numGridPoints = n; numGridPoints = n;
@ -141,9 +137,7 @@ void IncDrawVerts(){
} }
void SetDrawVerts( int n ){ void SetDrawVerts( int n ){
if ( drawVerts != 0 ) {
free( drawVerts ); free( drawVerts );
}
numDrawVerts = numDrawVerts =
numDrawVertsBuffer = n; numDrawVertsBuffer = n;
@ -152,9 +146,7 @@ void SetDrawVerts( int n ){
} }
void SetDrawSurfacesBuffer(){ void SetDrawSurfacesBuffer(){
if ( drawSurfaces != 0 ) {
free( drawSurfaces ); free( drawSurfaces );
}
numDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS; numDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS;
@ -162,9 +154,7 @@ void SetDrawSurfacesBuffer(){
} }
void SetDrawSurfaces( int n ){ void SetDrawSurfaces( int n ){
if ( drawSurfaces != 0 ) {
free( drawSurfaces ); free( drawSurfaces );
}
numDrawSurfaces = numDrawSurfaces =
numDrawSurfacesBuffer = n; numDrawSurfacesBuffer = n;
@ -173,19 +163,11 @@ void SetDrawSurfaces( int n ){
} }
void BspFilesCleanup(){ void BspFilesCleanup(){
if ( drawVerts != 0 ) {
free( drawVerts ); free( drawVerts );
}
if ( drawSurfaces != 0 ) {
free( drawSurfaces ); free( drawSurfaces );
}
if ( lightBytes != 0 ) {
free( lightBytes ); free( lightBytes );
}
if ( gridData != 0 ) {
free( gridData ); free( gridData );
} }
}
//============================================================================= //=============================================================================

View File

@ -87,9 +87,7 @@ void IncDrawVerts(){
} }
void SetDrawVerts( int n ){ void SetDrawVerts( int n ){
if ( bspDrawVerts != 0 ) {
free( bspDrawVerts ); free( bspDrawVerts );
}
numBSPDrawVerts = numBSPDrawVerts =
numBSPDrawVertsBuffer = n; numBSPDrawVertsBuffer = n;
@ -99,9 +97,7 @@ void SetDrawVerts( int n ){
int numBSPDrawSurfacesBuffer = 0; int numBSPDrawSurfacesBuffer = 0;
void SetDrawSurfacesBuffer(){ void SetDrawSurfacesBuffer(){
if ( bspDrawSurfaces != 0 ) {
free( bspDrawSurfaces ); free( bspDrawSurfaces );
}
numBSPDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS; numBSPDrawSurfacesBuffer = MAX_MAP_DRAW_SURFS;
@ -109,9 +105,7 @@ void SetDrawSurfacesBuffer(){
} }
void SetDrawSurfaces( int n ){ void SetDrawSurfaces( int n ){
if ( bspDrawSurfaces != 0 ) {
free( bspDrawSurfaces ); free( bspDrawSurfaces );
}
numBSPDrawSurfaces = numBSPDrawSurfaces =
numBSPDrawSurfacesBuffer = n; numBSPDrawSurfacesBuffer = n;
@ -120,19 +114,11 @@ void SetDrawSurfaces( int n ){
} }
void BSPFilesCleanup(){ void BSPFilesCleanup(){
if ( bspDrawVerts != 0 ) {
free( bspDrawVerts ); free( bspDrawVerts );
}
if ( bspDrawSurfaces != 0 ) {
free( bspDrawSurfaces ); free( bspDrawSurfaces );
}
if ( bspLightBytes != 0 ) {
free( bspLightBytes ); free( bspLightBytes );
}
if ( bspGridPoints != 0 ) {
free( bspGridPoints ); free( bspGridPoints );
} }
}

View File

@ -267,13 +267,9 @@ void ImageFree( image_t *image ){
/* free? */ /* free? */
if ( image->refCount <= 0 ) { if ( image->refCount <= 0 ) {
if ( image->name != NULL ) {
free( image->name ); free( image->name );
}
image->name = NULL; image->name = NULL;
if ( image->filename != NULL ) {
free( image->filename ); free( image->filename );
}
image->filename = NULL; image->filename = NULL;
free( image->pixels ); free( image->pixels );
image->width = 0; image->width = 0;

View File

@ -1856,9 +1856,7 @@ void SetupGrid( void ){
/* allocate lightgrid */ /* allocate lightgrid */
rawGridPoints = safe_calloc( numRawGridPoints * sizeof( *rawGridPoints ) ); rawGridPoints = safe_calloc( numRawGridPoints * sizeof( *rawGridPoints ) );
if ( bspGridPoints != NULL ) {
free( bspGridPoints ); free( bspGridPoints );
}
bspGridPoints = safe_calloc( numBSPGridPoints * sizeof( *bspGridPoints ) ); bspGridPoints = safe_calloc( numBSPGridPoints * sizeof( *bspGridPoints ) );
/* clear lightgrid */ /* clear lightgrid */

View File

@ -830,9 +830,7 @@ static int TriangulateTraceNode_r( int nodeNum ){
/* empty node? */ /* empty node? */
if ( node->numItems == 0 ) { if ( node->numItems == 0 ) {
node->maxItems = 0; node->maxItems = 0;
if ( node->items != NULL ) {
free( node->items ); free( node->items );
}
return node->numItems; return node->numItems;
} }
@ -873,9 +871,7 @@ static int TriangulateTraceNode_r( int nodeNum ){
} }
/* free windings */ /* free windings */
if ( windings != NULL ) {
free( windings ); free( windings );
}
/* return item count */ /* return item count */
return node->numItems; return node->numItems;

View File

@ -3863,9 +3863,7 @@ void SetupEnvelopes( qboolean forGrid, qboolean fastFlag ){
/* delete the light */ /* delete the light */
numCulledLights++; numCulledLights++;
*owner = light->next; *owner = light->next;
if ( light->w != NULL ) {
free( light->w ); free( light->w );
}
free( light ); free( light );
continue; continue;
} }
@ -4049,10 +4047,8 @@ void CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int nu
void FreeTraceLights( trace_t *trace ){ void FreeTraceLights( trace_t *trace ){
if ( trace->lights != NULL ) {
free( trace->lights ); free( trace->lights );
} }
}

View File

@ -3155,9 +3155,7 @@ void StoreSurfaceLightmaps( qboolean fastAllocate ){
timer_start = I_FloatTime(); timer_start = I_FloatTime();
/* count the bsp lightmaps and allocate space */ /* count the bsp lightmaps and allocate space */
if ( bspLightBytes != NULL ) {
free( bspLightBytes ); free( bspLightBytes );
}
if ( numBSPLightmaps == 0 || externalLightmaps ) { if ( numBSPLightmaps == 0 || externalLightmaps ) {
numBSPLightBytes = 0; numBSPLightBytes = 0;
bspLightBytes = NULL; bspLightBytes = NULL;

View File

@ -48,10 +48,8 @@ static void ExitQ3Map( void ){
/* flush xml send buffer, shut down connection */ /* flush xml send buffer, shut down connection */
Broadcast_Shutdown(); Broadcast_Shutdown();
BSPFilesCleanup(); BSPFilesCleanup();
if ( mapDrawSurfs != NULL ) {
free( mapDrawSurfs ); free( mapDrawSurfs );
} }
}

View File

@ -522,9 +522,7 @@ int MiniMapBSPMain( int argc, char **argv ){
minimap.samples = atoi( argv[i + 1] ); minimap.samples = atoi( argv[i + 1] );
i++; i++;
Sys_Printf( "Samples set to %i\n", minimap.samples ); Sys_Printf( "Samples set to %i\n", minimap.samples );
if ( minimap.sample_offsets ) {
free( minimap.sample_offsets ); free( minimap.sample_offsets );
}
minimap.sample_offsets = malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples ); minimap.sample_offsets = malloc( 2 * sizeof( *minimap.sample_offsets ) * minimap.samples );
MiniMapMakeSampleOffsets(); MiniMapMakeSampleOffsets();
} }
@ -532,9 +530,7 @@ int MiniMapBSPMain( int argc, char **argv ){
minimap.samples = atoi( argv[i + 1] ); minimap.samples = atoi( argv[i + 1] );
i++; i++;
Sys_Printf( "Random samples set to %i\n", minimap.samples ); Sys_Printf( "Random samples set to %i\n", minimap.samples );
if ( minimap.sample_offsets ) {
free( minimap.sample_offsets ); free( minimap.sample_offsets );
}
minimap.sample_offsets = NULL; minimap.sample_offsets = NULL;
} }
else if ( !strcmp( argv[ i ], "-border" ) ) { else if ( !strcmp( argv[ i ], "-border" ) ) {

View File

@ -277,14 +277,10 @@ void ClearSurface( mapDrawSurface_t *ds ){
ds->planar = qfalse; ds->planar = qfalse;
ds->planeNum = -1; ds->planeNum = -1;
ds->numVerts = 0; ds->numVerts = 0;
if ( ds->verts != NULL ) {
free( ds->verts ); free( ds->verts );
}
ds->verts = NULL; ds->verts = NULL;
ds->numIndexes = 0; ds->numIndexes = 0;
if ( ds->indexes != NULL ) {
free( ds->indexes ); free( ds->indexes );
}
ds->indexes = NULL; ds->indexes = NULL;
numClearedSurfaces++; numClearedSurfaces++;
} }