Fixed few memory leaks

Fixed few memory leaks

diff --git a/src/engine/GPURenderer/r_glimp.cpp b/src/engine/GPURenderer/r_glimp.cpp
index 2bfbef7..af6cbba 100644
--- a/src/engine/GPURenderer/r_glimp.cpp
+++ b/src/engine/GPURenderer/r_glimp.cpp
@@ -538,7 +538,12 @@ static sint GLimp_SetMode( sint mode, bool fullscreen, bool noborder, bool fixed
                     }
                     break;
                 case 1:
-                    if( depthBits == 24 )
+                    if( depthBits == 32 )
+                    {
+                        depthBits = 24;
+                    }
+                    else if( depthBits == 24 )
+                    
                     {
                         depthBits = 16;
                     }
diff --git a/src/engine/GPURenderer/r_image_tga.cpp b/src/engine/GPURenderer/r_image_tga.cpp
index c817f74..851818f 100644
--- a/src/engine/GPURenderer/r_image_tga.cpp
+++ b/src/engine/GPURenderer/r_image_tga.cpp
@@ -72,6 +72,7 @@ void R_LoadTGA( pointer name, uchar8** pic, sint* width, sint* height )
     
     if( length < 18 )
     {
+        fileSystem->FreeFile( buffer.v );
         Com_Error( ERR_DROP, "LoadTGA: header too short (%s)", name );
     }
     
@@ -133,8 +134,12 @@ void R_LoadTGA( pointer name, uchar8** pic, sint* width, sint* height )
     if( targa_header.id_length != 0 )
     {
         if( buf_p + targa_header.id_length > end )
+        {
+            Z_Free( targa_rgba );
+            fileSystem->FreeFile( buffer.v );
             Com_Error( ERR_DROP, "LoadTGA: header too short (%s)", name );
-            
+        }
+        
         buf_p += targa_header.id_length;  // skip TARGA image comment
     }
     
@@ -142,6 +147,8 @@ void R_LoadTGA( pointer name, uchar8** pic, sint* width, sint* height )
     {
         if( buf_p + columns * rows * targa_header.pixel_size / 8 > end )
         {
+            Z_Free( targa_rgba );
+            fileSystem->FreeFile( buffer.v );
             Com_Error( ERR_DROP, "LoadTGA: file truncated (%s)", name );
         }
         
diff --git a/src/engine/framework/CVarSystem.cpp b/src/engine/framework/CVarSystem.cpp
index 81e5997..2f1308c 100644
--- a/src/engine/framework/CVarSystem.cpp
+++ b/src/engine/framework/CVarSystem.cpp
@@ -1133,6 +1133,7 @@ void idCVarSystemLocal::Set_f( void )
     }
     
     cvarSystemLocal.GetSet2( cmdSystem->Argv( 1 ), Com_UnquoteStr( value ), false );
+    free( value );
 }
 
 /*
diff --git a/src/engine/soundSystem/sndSystem_dma.cpp b/src/engine/soundSystem/sndSystem_dma.cpp
index 51fe3fd..6b1a7a3 100644
--- a/src/engine/soundSystem/sndSystem_dma.cpp
+++ b/src/engine/soundSystem/sndSystem_dma.cpp
@@ -290,8 +290,10 @@ void SOrig_Shutdown( void )
     }
     
     SNDDMA_Shutdown();
+    SND_shutdown();
     
     s_soundStarted = 0;
+    s_numSfx = 0;
     
     cmdSystem->RemoveCommand( "play" );
     cmdSystem->RemoveCommand( "music" );
diff --git a/src/engine/soundSystem/sndSystem_local.hpp b/src/engine/soundSystem/sndSystem_local.hpp
index dc1707a..1b6d858 100644
--- a/src/engine/soundSystem/sndSystem_local.hpp
+++ b/src/engine/soundSystem/sndSystem_local.hpp
@@ -180,6 +180,7 @@ bool S_LoadSound( sfx_t* sfx );
 void SND_free( sndBuffer* v );
 sndBuffer* SND_malloc( void );
 void SND_setup( void );
+void SND_shutdown( void );
 
 void S_PaintChannels( sint endtime );
 
diff --git a/src/engine/soundSystem/sndSystem_mem.cpp b/src/engine/soundSystem/sndSystem_mem.cpp
index 20d37df..b5c33d4 100644
--- a/src/engine/soundSystem/sndSystem_mem.cpp
+++ b/src/engine/soundSystem/sndSystem_mem.cpp
@@ -84,6 +84,12 @@ redo:
     return v;
 }
 
+void SND_shutdown( void )
+{
+    free( sfxScratchBuffer );
+    free( buffer );
+}
+
 /*
 ===============
 SND_setup

GitHub
sha: ac24be80