move csqc_progdata and csqc_progdata_deflated from sv to svs to fix a memory leak
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 4 Apr 2009 13:42:09 +0000 (13:42 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 4 Apr 2009 13:42:09 +0000 (13:42 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8853 d7cf8633-e32d-0410-b094-e92efae38249

host.c
server.h
sv_main.c

diff --git a/host.c b/host.c
index eb2311f..c8521f2 100644 (file)
--- a/host.c
+++ b/host.c
@@ -549,14 +549,6 @@ void Host_ShutdownServer(void)
 
        NetConn_CloseServerPorts();
 
-       if(sv.csqc_progdata)
-       {
-               Con_DPrintf("Unloading CSQC data.\n");
-               Mem_Free(sv.csqc_progdata);
-               if(sv.csqc_progdata_deflated)
-                       Mem_Free(sv.csqc_progdata_deflated);
-       }
-
        sv.active = false;
 //
 // clear structures
index 555bef6..1d71703 100644 (file)
--- a/server.h
+++ b/server.h
@@ -48,6 +48,12 @@ typedef struct server_static_s
        float perf_acc_offset_squared;
        float perf_acc_offset_max;
        int perf_acc_offset_samples;
+
+       // csqc stuff
+       unsigned char *csqc_progdata;
+       size_t csqc_progsize_deflated;
+       unsigned char *csqc_progdata_deflated;
+
 } server_static_t;
 
 //=============================================================================
@@ -87,9 +93,6 @@ typedef struct server_s
        int csqc_progcrc; // -1 = no progs
        int csqc_progsize; // -1 = no progs
        char csqc_progname[MAX_QPATH]; // copied from csqc_progname at level start
-       unsigned char *csqc_progdata;
-       size_t csqc_progsize_deflated;
-       unsigned char *csqc_progdata_deflated;
 
        // collision culling data
        world_t world;
index be2111c..db27151 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -800,7 +800,7 @@ void SV_SendServerinfo (client_t *client)
                        sb.data = (unsigned char *) buf;
                        sb.maxsize = sizeof(buf);
                        i = 0;
-                       while(MakeDownloadPacket(sv.csqc_progname, sv.csqc_progdata, sv.csqc_progsize, sv.csqc_progcrc, i++, &sb, sv.protocol))
+                       while(MakeDownloadPacket(sv.csqc_progname, svs.csqc_progdata, sv.csqc_progsize, sv.csqc_progcrc, i++, &sb, sv.protocol))
                                SV_WriteDemoMessage(client, &sb, false);
                }
 
@@ -2234,9 +2234,9 @@ static void SV_Download_f(void)
                Con_DPrintf("Downloading %s to %s\n", host_client->download_name, host_client->name);
 
                if(host_client->download_deflate)
-                       host_client->download_file = FS_FileFromData(sv.csqc_progdata_deflated, sv.csqc_progsize_deflated, true);
+                       host_client->download_file = FS_FileFromData(svs.csqc_progdata_deflated, svs.csqc_progsize_deflated, true);
                else
-                       host_client->download_file = FS_FileFromData(sv.csqc_progdata, sv.csqc_progsize, true);
+                       host_client->download_file = FS_FileFromData(svs.csqc_progdata, sv.csqc_progsize, true);
                
                // no, no space is needed between %s and %s :P
                Host_ClientCommands("\ncl_downloadbegin %i %s%s\n", (int)FS_FileSize(host_client->download_file), host_client->download_name, extensions);
@@ -2638,37 +2638,37 @@ void SV_Prepare_CSQC(void)
 {
        fs_offset_t progsize;
 
-       if(sv.csqc_progdata)
+       if(svs.csqc_progdata)
        {
                Con_DPrintf("Unloading old CSQC data.\n");
-               Mem_Free(sv.csqc_progdata);
-               if(sv.csqc_progdata_deflated)
-                       Mem_Free(sv.csqc_progdata_deflated);
+               Mem_Free(svs.csqc_progdata);
+               if(svs.csqc_progdata_deflated)
+                       Mem_Free(svs.csqc_progdata_deflated);
        }
 
-       sv.csqc_progdata = NULL;
-       sv.csqc_progdata_deflated = NULL;
+       svs.csqc_progdata = NULL;
+       svs.csqc_progdata_deflated = NULL;
        
        Con_Print("Loading csprogs.dat\n");
 
        sv.csqc_progname[0] = 0;
-       sv.csqc_progdata = FS_LoadFile(csqc_progname.string, sv_mempool, false, &progsize);
+       svs.csqc_progdata = FS_LoadFile(csqc_progname.string, sv_mempool, false, &progsize);
 
        if(progsize > 0)
        {
                size_t deflated_size;
                
                sv.csqc_progsize = (int)progsize;
-               sv.csqc_progcrc = CRC_Block(sv.csqc_progdata, progsize);
+               sv.csqc_progcrc = CRC_Block(svs.csqc_progdata, progsize);
                strlcpy(sv.csqc_progname, csqc_progname.string, sizeof(sv.csqc_progname));
                Con_Printf("server detected csqc progs file \"%s\" with size %i and crc %i\n", sv.csqc_progname, sv.csqc_progsize, sv.csqc_progcrc);
 
                Con_Print("Compressing csprogs.dat\n");
                //unsigned char *FS_Deflate(const unsigned char *data, size_t size, size_t *deflated_size, int level, mempool_t *mempool);
-               sv.csqc_progdata_deflated = FS_Deflate(sv.csqc_progdata, progsize, &deflated_size, -1, sv_mempool);
-               sv.csqc_progsize_deflated = (int)deflated_size;
+               svs.csqc_progdata_deflated = FS_Deflate(svs.csqc_progdata, progsize, &deflated_size, -1, sv_mempool);
+               svs.csqc_progsize_deflated = (int)deflated_size;
                Con_Printf("Deflated: %g%%\n", 100.0 - 100.0 * (deflated_size / (float)progsize));
-               Con_DPrintf("Uncompressed: %u\nCompressed:   %u\n", (unsigned)sv.csqc_progsize, (unsigned)sv.csqc_progsize_deflated);
+               Con_DPrintf("Uncompressed: %u\nCompressed:   %u\n", (unsigned)sv.csqc_progsize, (unsigned)svs.csqc_progsize_deflated);
        }
 }
 
@@ -2792,13 +2792,6 @@ void SV_SpawnServer (const char *server)
        //Cvar_SetValue ("skill", (float)current_skill);
        current_skill = (int)(skill.value + 0.5);
 
-       if(sv.csqc_progdata)
-       {
-               Con_DPrintf("Unloading CSQC data.\n");
-               Mem_Free(sv.csqc_progdata);
-               if(sv.csqc_progdata_deflated)
-                       Mem_Free(sv.csqc_progdata_deflated);
-       }
 //
 // set up the new server
 //