]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
every malloc/calloc/free converted to qmalloc/qfree with tracking (memstats command...
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 29 Jan 2001 08:14:37 +0000 (08:14 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 29 Jan 2001 08:14:37 +0000 (08:14 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@141 d7cf8633-e32d-0410-b094-e92efae38249

24 files changed:
common.c
common.h
fractalnoise.c
gl_draw.c
gl_models.c
gl_poly.c
gl_rsurf.c
gl_screen.c
gl_textures.c
gl_warp.c
hcompress.c
host.c
image.c
model_alias.c
model_brush.c
model_shared.c
model_sprite.c
palette.c
r_part.c
snd_mem.c
sys_linux.c
sys_win.c
sys_wind.c
wad.c

index 71624aa26b992bf0bd5718e6f8c3e4d915147735..bd8d2f8b4d7f1cd4ba7efcb0152ffe4b433c09b2 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1167,6 +1167,38 @@ void COM_InitArgv (int argc, char **argv)
 }
 
 
+unsigned int qmalloctotal_alloc, qmalloctotal_alloccount, qmalloctotal_free, qmalloctotal_freecount;
+
+void *qmalloc(unsigned int size)
+{
+       unsigned int *mem;
+       qmalloctotal_alloc += size;
+       qmalloctotal_alloccount++;
+       mem = malloc(size+sizeof(unsigned int));
+       *mem = size;
+       return (void *)(mem + 1);
+}
+
+void qfree(void *mem)
+{
+       unsigned int *m;
+       m = mem;
+       m--; // back up to size
+       qmalloctotal_free += *m; // size
+       qmalloctotal_freecount++;
+       free(m);
+}
+
+void GL_TextureStats_PrintTotal(void);
+extern int hunk_low_used, hunk_high_used, hunk_size;
+void COM_Memstats_f(void)
+{
+       Con_Printf("%i malloc calls totalling %i bytes (%.4gMB)\n%i free calls totalling %i bytes (%.4gMB)\n%i bytes (%.4gMB) currently allocated\n", qmalloctotal_alloccount, qmalloctotal_alloc, qmalloctotal_alloc / 1048576.0, qmalloctotal_freecount, qmalloctotal_free, qmalloctotal_free / 1048576.0, qmalloctotal_alloc - qmalloctotal_free, (qmalloctotal_alloc - qmalloctotal_free) / 1048576.0);
+       GL_TextureStats_PrintTotal();
+       Con_Printf ("%i bytes (%.4gMB) of %.4gMB hunk in use\n", hunk_low_used + hunk_high_used, (hunk_low_used + hunk_high_used) / 1048576.0, hunk_size / 1048576.0);
+}
+
+
 /*
 ================
 COM_Init
@@ -1201,6 +1233,7 @@ void COM_Init (char *basedir)
        Cvar_RegisterVariable (&registered);
        Cvar_RegisterVariable (&cmdline);
        Cmd_AddCommand ("path", COM_Path_f);
+       Cmd_AddCommand ("memstats", COM_Memstats_f);
 
        COM_InitFilesystem ();
        COM_CheckRegistered ();
@@ -1617,7 +1650,7 @@ byte *COM_LoadFile (char *path, int usehunk, qboolean quiet)
                        buf = loadbuf;
        }
        else if (usehunk == 5)
-               buf = malloc (len+1);
+               buf = qmalloc (len+1);
        else
                Sys_Error ("COM_LoadFile: bad usehunk");
 
@@ -1710,7 +1743,7 @@ pack_t *COM_LoadPackFile (char *packfile)
 
        newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile");
 
-       info = malloc(sizeof(*info)*MAX_FILES_IN_PACK);
+       info = qmalloc(sizeof(*info)*MAX_FILES_IN_PACK);
        Sys_FileSeek (packhandle, header.dirofs);
        Sys_FileRead (packhandle, (void *)info, header.dirlen);
 
@@ -1730,7 +1763,7 @@ pack_t *COM_LoadPackFile (char *packfile)
                newfiles[i].filepos = LittleLong(info[i].filepos);
                newfiles[i].filelen = LittleLong(info[i].filelen);
        }
-       free(info);
+       qfree(info);
 
        pack = Hunk_Alloc (sizeof (pack_t));
        strcpy (pack->filename, packfile);
@@ -1923,4 +1956,3 @@ int COM_FileExists(char *filename)
 
        return false;
 }
-
index 152112cbf6030bac6d9acffbd68e1165097f3102..051b2acda0d64bd48a16908712d15d865fc2d5e7 100644 (file)
--- a/common.h
+++ b/common.h
@@ -31,6 +31,11 @@ typedef enum {false, true}   qboolean;
 
 //============================================================================
 
+extern void *qmalloc(unsigned int size);
+extern void qfree(void *mem);
+
+//============================================================================
+
 typedef struct sizebuf_s
 {
        qboolean        allowoverflow;  // if false, do a Sys_Error
index c03039a74f62218f484ecd8f1416584c19a8f27b..e9899a47f84771e4bc3e22c2514ad20d514d0575 100644 (file)
@@ -1,5 +1,5 @@
 
-#include <stdlib.h>
+#include "quakedef.h"
 
 void fractalnoise(unsigned char *noise, int size, int startgrid)
 {
@@ -8,7 +8,8 @@ void fractalnoise(unsigned char *noise, int size, int startgrid)
 #define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
        if (startgrid > size)
                startgrid = size;
-       noisebuf = calloc(size*size, sizeof(int));
+       noisebuf = qmalloc(size*size*sizeof(int));
+       memset(noisebuf, 0, size*size*sizeof(int));
 
        amplitude = 32767;
        // quick 1x1 case which the rest of the code can't handle
@@ -56,6 +57,6 @@ void fractalnoise(unsigned char *noise, int size, int startgrid)
        for (y = 0;y < size;y++)
                for (x = 0;x < size;x++)
                        *noise++ = (n(x,y) - min) * 255 / max;
-       free(noisebuf);
+       qfree(noisebuf);
 #undef n
 }
\ No newline at end of file
index bad2c8c711cfe2db24a1a25a11e985f59a88b4c3..8b0a43783c17af66c68a224457207ee79a80732a 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -209,7 +209,7 @@ qpic_t      *Draw_CachePic (char *path)
 //
 // load the pic from disk
 //
-       dat = (qpic_t *)COM_LoadTempFile (path, false);
+       dat = (qpic_t *)COM_LoadMallocFile (path, false);
        if (!dat)
                Sys_Error ("Draw_CachePic: failed to load %s", path);
        SwapPic (dat);
@@ -232,6 +232,8 @@ qpic_t      *Draw_CachePic (char *path)
        gl->tl = 0;
        gl->th = 1;
 
+       qfree(dat);
+
        return &pic->pic;
 }
 
@@ -484,12 +486,12 @@ void Draw_PicTranslate (int x, int y, qpic_t *pic, byte *translation)
 
        c = pic->width * pic->height;
        src = menuplyr_pixels;
-       dest = trans = malloc(c);
+       dest = trans = qmalloc(c);
        for (i = 0;i < c;i++)
                *dest++ = translation[*src++];
 
        c = GL_LoadTexture ("translatedplayerpic", pic->width, pic->height, trans, false, true, 1);
-       free(trans);
+       qfree(trans);
 
        if (!r_render.value)
                return;
index 594ca0faef282ce495347fbdade03b4cfd8274fc..87adbe99d39548dc95b0f0302d9abff63f23bc0f 100644 (file)
@@ -30,19 +30,19 @@ void makechrometexture()
 void gl_models_start()
 {
        // allocate vertex processing arrays
-       aliasvert = malloc(sizeof(float[MD2MAX_VERTS][3]));
-       aliasvertnorm = malloc(sizeof(float[MD2MAX_VERTS][3]));
-       aliasvertcolor = malloc(sizeof(byte[MD2MAX_VERTS][4]));
-       aliasvertcolor2 = malloc(sizeof(byte[MD2MAX_VERTS][4])); // used temporarily for tinted coloring
+       aliasvert = qmalloc(sizeof(float[MD2MAX_VERTS][3]));
+       aliasvertnorm = qmalloc(sizeof(float[MD2MAX_VERTS][3]));
+       aliasvertcolor = qmalloc(sizeof(byte[MD2MAX_VERTS][4]));
+       aliasvertcolor2 = qmalloc(sizeof(byte[MD2MAX_VERTS][4])); // used temporarily for tinted coloring
        makechrometexture();
 }
 
 void gl_models_shutdown()
 {
-       free(aliasvert);
-       free(aliasvertnorm);
-       free(aliasvertcolor);
-       free(aliasvertcolor2);
+       qfree(aliasvert);
+       qfree(aliasvertnorm);
+       qfree(aliasvertcolor);
+       qfree(aliasvertcolor2);
 }
 
 void GL_Models_Init()
index 1f18658e143c1ca2ac5ffb939a1409acec6e6e58..4252170e3119cc3a8d978a462ae773cd51d6604f 100644 (file)
--- a/gl_poly.c
+++ b/gl_poly.c
@@ -37,26 +37,26 @@ float transreciptable[256];
 void gl_poly_start()
 {
        int i;
-       transvert = malloc(MAX_TRANSVERTS * sizeof(transvert_t));
-       transpoly = malloc(MAX_TRANSPOLYS * sizeof(transpoly_t));
-       transpolyindex = malloc(MAX_TRANSPOLYS * sizeof(unsigned short));
-       wallvert = malloc(MAX_WALLVERTS * sizeof(wallvert_t));
-       wallpoly = malloc(MAX_WALLPOLYS * sizeof(wallpoly_t));
-       skyvert = malloc(MAX_SKYVERTS * sizeof(skyvert_t));
-       skypoly = malloc(MAX_SKYPOLYS * sizeof(skypoly_t));
+       transvert = qmalloc(MAX_TRANSVERTS * sizeof(transvert_t));
+       transpoly = qmalloc(MAX_TRANSPOLYS * sizeof(transpoly_t));
+       transpolyindex = qmalloc(MAX_TRANSPOLYS * sizeof(unsigned short));
+       wallvert = qmalloc(MAX_WALLVERTS * sizeof(wallvert_t));
+       wallpoly = qmalloc(MAX_WALLPOLYS * sizeof(wallpoly_t));
+       skyvert = qmalloc(MAX_SKYVERTS * sizeof(skyvert_t));
+       skypoly = qmalloc(MAX_SKYPOLYS * sizeof(skypoly_t));
        transreciptable[0] = 0.0f;
        for (i = 1;i < 256;i++)
                transreciptable[i] = 1.0f / i;
 }
 void gl_poly_shutdown()
 {
-       free(transvert);
-       free(transpoly);
-       free(transpolyindex);
-       free(wallvert);
-       free(wallpoly);
-       free(skyvert);
-       free(skypoly);
+       qfree(transvert);
+       qfree(transpoly);
+       qfree(transpolyindex);
+       qfree(wallvert);
+       qfree(wallpoly);
+       qfree(skyvert);
+       qfree(skypoly);
 }
 
 void GL_Poly_Init()
index 21d9d646bc5976db6ae0b4bd23115bfff41e6136..4377edc717e039979a0205f839d5510e5d554ccf 100644 (file)
@@ -1082,7 +1082,10 @@ int AllocBlock (int w, int h, short *x, short *y)
                if (nosubimagefragments || nosubimage)
                {
                        if (!lightmaps[texnum])
-                               lightmaps[texnum] = calloc(BLOCK_WIDTH*BLOCK_HEIGHT*4, 1);
+                       {
+                               lightmaps[texnum] = qmalloc(BLOCK_WIDTH*BLOCK_HEIGHT*4);
+                               memset(lightmaps[texnum], 0, BLOCK_WIDTH*BLOCK_HEIGHT*4);
+                       }
                }
                // LordHavoc: clear texture to blank image, fragments are uploaded using subimage
                else if (!allocated[texnum][0])
index 045afa6e910341a1ab8ab0d04026b811473dd2e6..ab123c0c80ef2dce67b8efd0c846c6eaa5022c8f 100644 (file)
@@ -615,11 +615,11 @@ void SCR_ScreenShot_f (void)
                return;
        }
 
-       buffer = malloc(glwidth*glheight*3);
+       buffer = qmalloc(glwidth*glheight*3);
        glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); 
        Image_WriteTGARGB_preflipped(filename, glwidth, glheight, buffer);
 
-       free (buffer);
+       qfree(buffer);
        Con_Printf ("Wrote %s\n", filename);
 }
 
index f90f8781276aa55eb9a74b7854cdd95bfd086c99..952ea1f881c4deaf802281b4a961844eb8714b4b 100644 (file)
@@ -126,6 +126,15 @@ void GL_TextureStats_f(void)
        Con_Printf("%i textures, totalling %.3f mbytes\n", numgltextures, t / 1024.0 / 1024.0);
 }
 
+void GL_TextureStats_PrintTotal(void)
+{
+       int i, t = 0;
+       gltexture_t *glt;
+       for (i = 0, glt = gltextures;i < numgltextures;i++, glt++)
+               t += glt->totaltexels;
+       Con_Printf("%i textures, totalling %.3f mbytes\n", numgltextures, t / 1024.0 / 1024.0);
+}
+
 extern int buildnumber;
 
 char engineversion[40];
@@ -228,8 +237,8 @@ void GL_ResampleTexture (void *indata, int inwidth, int inheight, void *outdata,
                out = outdata;
                fstep = (int) (inheight*65536.0f/outheight);
 
-               row1 = malloc(outwidth*4);
-               row2 = malloc(outwidth*4);
+               row1 = qmalloc(outwidth*4);
+               row2 = qmalloc(outwidth*4);
                inrow = indata;
                oldy = 0;
                GL_ResampleTextureLerpLine (inrow, row1, inwidth, outwidth);
@@ -276,8 +285,8 @@ void GL_ResampleTexture (void *indata, int inwidth, int inheight, void *outdata,
                                row1 -= outwidth*4;
                        }
                }
-               free(row1);
-               free(row2);
+               qfree(row1);
+               qfree(row2);
        }
        else
        {
@@ -305,7 +314,7 @@ void GL_ResampleTexture (void *indata, int inwidth, int inheight, void *outdata,
 void GL_FreeTexels(gltexture_t *glt)
 {
        if (glt->texels[0])
-               free(glt->texels[0]);
+               qfree(glt->texels[0]);
        glt->texels[0] = 0;
 }
 
@@ -345,7 +354,7 @@ void GL_AllocTexels(gltexture_t *glt, int width, int height, int mipmapped)
                glt->totaltexels = size;
                while (i < MAXMIPS)
                        glt->texels[i++] = NULL;
-               glt->texels[0] = malloc(size);
+               glt->texels[0] = qmalloc(size);
                for (i = 1;i < MAXMIPS && glt->texels[i];i++)
                        glt->texels[i] += (int) glt->texels[0];
        }
@@ -353,7 +362,7 @@ void GL_AllocTexels(gltexture_t *glt, int width, int height, int mipmapped)
        {
                size = width*height*4;
                glt->totaltexels = size;
-               glt->texels[0] = malloc(size);
+               glt->texels[0] = qmalloc(size);
                for (i = 1;i < MAXMIPS;i++)
                        glt->texels[i] = NULL;
        }
@@ -532,7 +541,7 @@ GL_LoadTexture_setup:
        else if (width == width2 && height == height2) // perfect match for top level, but needs to be reduced
        {
                byte *temptexels2;
-               temptexels2 = malloc(width2*height2*4); // scaleup buffer
+               temptexels2 = qmalloc(width2*height2*4); // scaleup buffer
                if (bytesperpixel == 1) // 8bit
                        Image_Copy8bitRGBA(data, temptexels2, width*height, d_8to24table);
                else
@@ -547,13 +556,13 @@ GL_LoadTexture_setup:
                        else
                                GL_MipReduce(temptexels2, temptexels2, w, h, width3, height3);
                }
-               free(temptexels2);
+               qfree(temptexels2);
        }
        else // scaling...
        {
                byte *temptexels;
                // pre-scaleup buffer
-               temptexels = malloc(width*height*4);
+               temptexels = qmalloc(width*height*4);
                if (bytesperpixel == 1) // 8bit
                        Image_Copy8bitRGBA(data, temptexels, width*height, d_8to24table);
                else
@@ -561,7 +570,7 @@ GL_LoadTexture_setup:
                if (width2 != width3 || height2 != height3) // reduced by gl_pic_mip or gl_max_size
                {
                        byte *temptexels2;
-                       temptexels2 = malloc(width2*height2*4); // scaleup buffer
+                       temptexels2 = qmalloc(width2*height2*4); // scaleup buffer
                        GL_ResampleTexture(temptexels, width, height, temptexels2, width2, height2);
                        while (width2 > width3 || height2 > height3)
                        {
@@ -573,11 +582,11 @@ GL_LoadTexture_setup:
                                else
                                        GL_MipReduce(temptexels2, temptexels2, w, h, width3, height3);
                        }
-                       free(temptexels2);
+                       qfree(temptexels2);
                }
                else // copy directly
                        GL_ResampleTexture(temptexels, width, height, glt->texels[0], width2, height2);
-               free(temptexels);
+               qfree(temptexels);
        }
        if (alpha)
        {
index d15a34bec6067b793762c8db07466a714ce42033..495f59399f60506883b04e27bde5e1c19431b17f 100644 (file)
--- a/gl_warp.c
+++ b/gl_warp.c
@@ -212,7 +212,7 @@ void R_LoadSkyBox (void)
                        }
                }
                skyboxside[i] = GL_LoadTexture(va("skyboxside%d", i), image_width, image_height, image_rgba, false, false, 4);
-               free (image_rgba);
+               qfree(image_rgba);
        }
 }
 
index 1db33de3663a4108664e8947ab84cb9617fc7582..9e36868b2d611998dffaf91947a1b0215d6b2b51 100644 (file)
@@ -170,8 +170,8 @@ int hcompress_compress(void *indata, void *outdata, int size)
                int length; // length of the chain
        } hashindex[256][256];
        int *hashtable;
-       token = malloc(size*sizeof(struct hctoken));
-       hashtable = malloc(size*sizeof(int));
+       token = qmalloc(size*sizeof(struct hctoken));
+       hashtable = qmalloc(size*sizeof(int));
        in = indata;
        memset(&hashindex, 0, sizeof(hashindex));
        // count the chain lengths
diff --git a/host.c b/host.c
index 59b4db59dd9e068e4ae1803f6f739e7bc05a0efe..f9dc58d55545ca586581ed347fbdb19295dfac12 100644 (file)
--- a/host.c
+++ b/host.c
@@ -750,12 +750,12 @@ void Host_InitVCR ()
                        Sys_Error("Invalid signature in vcr file\n");
 
                Sys_FileRead (vcrFile, &com_argc, sizeof(int));
-               com_argv = malloc(com_argc * sizeof(char *));
+               com_argv = qmalloc(com_argc * sizeof(char *));
                com_argv[0] = host_parms.argv[0];
                for (i = 0; i < com_argc; i++)
                {
                        Sys_FileRead (vcrFile, &len, sizeof(int));
-                       p = malloc(len);
+                       p = qmalloc(len);
                        Sys_FileRead (vcrFile, p, len);
                        com_argv[i+1] = p;
                }
diff --git a/image.c b/image.c
index 4ba317076f64451a9327387cdcd16bf4dccb9a26..d12ed7123b58572197d17e6a757787e95a0180bd 100644 (file)
--- a/image.c
+++ b/image.c
@@ -130,7 +130,7 @@ byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
        fseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
 
        count = (pcx->xmax+1) * (pcx->ymax+1);
-       image_rgba = malloc( count * 4);
+       image_rgba = qmalloc( count * 4);
 
        for (y=0 ; y<=pcx->ymax ; y++)
        {
@@ -258,7 +258,7 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
        rows = targa_header.height;
        numPixels = columns * rows;
 
-       image_rgba = malloc (numPixels*4);
+       image_rgba = qmalloc(numPixels*4);
        
        if (targa_header.id_length != 0)
                fseek(fin, targa_header.id_length, SEEK_CUR);  // skip TARGA image comment
@@ -397,7 +397,7 @@ byte* LoadLMP (FILE *f, int matchwidth, int matchheight)
        if (matchheight && height != matchheight)
                return NULL;
 
-       image_rgba = malloc(width*height*4);
+       image_rgba = qmalloc(width*height*4);
        fread(image_rgba + width*height*3, 1, width*height, f);
        fclose(f);
 
@@ -490,7 +490,7 @@ byte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, in
                return data; // some transparency
        else
        {
-               free(data);
+               qfree(data);
                return NULL; // all opaque
        }
 }
@@ -502,7 +502,7 @@ int loadtextureimage (char* filename, int matchwidth, int matchheight, qboolean
        if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
                return 0;
        texnum = GL_LoadTexture (filename, image_width, image_height, data, mipmap, true, 4);
-       free(data);
+       qfree(data);
        return texnum;
 }
 
@@ -513,7 +513,7 @@ int loadtextureimagemask (char* filename, int matchwidth, int matchheight, qbool
        if (!(data = loadimagepixelsmask (filename, complain, matchwidth, matchheight)))
                return 0;
        texnum = GL_LoadTexture (filename, image_width, image_height, data, mipmap, true, 4);
-       free(data);
+       qfree(data);
        return texnum;
 }
 
@@ -530,12 +530,12 @@ int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, q
        count = image_makemask(data, data, image_width * image_height);
        if (count)
        {
-               filename2 = malloc(strlen(filename) + 6);
+               filename2 = qmalloc(strlen(filename) + 6);
                sprintf(filename2, "%s_mask", filename);
                image_masktexnum = GL_LoadTexture (filename2, image_width, image_height, data, mipmap, true, 4);
-               free(filename2);
+               qfree(filename2);
        }
-       free(data);
+       qfree(data);
        return texnum;
 }
 
@@ -543,7 +543,7 @@ void Image_WriteTGARGB_preflipped (char *filename, int width, int height, byte *
 {
        byte *buffer, *in, *out, *end;
 
-       buffer = malloc(width*height*3 + 18);
+       buffer = qmalloc(width*height*3 + 18);
 
        memset (buffer, 0, 18);
        buffer[2] = 2;          // uncompressed type
@@ -565,7 +565,7 @@ void Image_WriteTGARGB_preflipped (char *filename, int width, int height, byte *
        }
        COM_WriteFile (filename, buffer, width*height*3 + 18 );
 
-       free(buffer);
+       qfree(buffer);
 }
 
 void Image_WriteTGARGB (char *filename, int width, int height, byte *data)
@@ -573,7 +573,7 @@ void Image_WriteTGARGB (char *filename, int width, int height, byte *data)
        int y;
        byte *buffer, *in, *out, *end;
 
-       buffer = malloc(width*height*3 + 18);
+       buffer = qmalloc(width*height*3 + 18);
 
        memset (buffer, 0, 18);
        buffer[2] = 2;          // uncompressed type
@@ -598,7 +598,7 @@ void Image_WriteTGARGB (char *filename, int width, int height, byte *data)
        }
        COM_WriteFile (filename, buffer, width*height*3 + 18 );
 
-       free(buffer);
+       qfree(buffer);
 }
 
 void Image_WriteTGARGBA (char *filename, int width, int height, byte *data)
@@ -606,7 +606,7 @@ void Image_WriteTGARGBA (char *filename, int width, int height, byte *data)
        int y;
        byte *buffer, *in, *out, *end;
 
-       buffer = malloc(width*height*4 + 18);
+       buffer = qmalloc(width*height*4 + 18);
 
        memset (buffer, 0, 18);
        buffer[2] = 2;          // uncompressed type
@@ -632,5 +632,5 @@ void Image_WriteTGARGBA (char *filename, int width, int height, byte *data)
        }
        COM_WriteFile (filename, buffer, width*height*4 + 18 );
 
-       free(buffer);
+       qfree(buffer);
 }
index 4d4e5885e7887fa79818ba526bce62aa50bbde14..c6b72f66584fc8f83e09e2562af304459003d4b3 100644 (file)
@@ -299,7 +299,7 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int width, in
                Host_Error ("Mod_LoadAliasModel: Invalid # of skins: %d\n", numskins);
 
        s = width * height;
-       skintemp = malloc(s);
+       skintemp = qmalloc(s);
 
        // LordHavoc: skim the data, measure the number of skins and number of groups
        skinranges = numskins;
@@ -373,7 +373,7 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype, int width, in
                }
        }
        loadmodel->numskins = numskins;
-       free(skintemp);
+       qfree(skintemp);
 
        return (void *)pskintype;
 }
@@ -691,7 +691,7 @@ void Mod_LoadQ2AliasModel (model_t *mod, void *buffer)
        start = Hunk_LowMark ();
 
 //     if (!temptris)
-//             temptris = malloc(sizeof(temptris_t) * MD2MAX_TRIANGLES);
+//             temptris = qmalloc(sizeof(temptris_t) * MD2MAX_TRIANGLES);
 
        pinmodel = (md2_t *)buffer;
 
index db1e398c8f1be40e2b5f5420d2efa2a66f79210c..c070d4217a4126a3a554c47beb82b4d5f0984ac8 100644 (file)
@@ -206,7 +206,7 @@ void Mod_LoadTextures (lump_t *l)
                        {
                                char name[64];
                                byte *data2;
-                               data2 = malloc(tx->width*tx->height);
+                               data2 = qmalloc(tx->width*tx->height);
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
                                tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
@@ -215,7 +215,7 @@ void Mod_LoadTextures (lump_t *l)
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
                                tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
-                               free(data2);
+                               qfree(data2);
                        }
                        else
                        {
@@ -224,7 +224,7 @@ void Mod_LoadTextures (lump_t *l)
                        }
                }
                if (freeimage)
-                       free(data);
+                       qfree(data);
        }
 
 //
index 80ca54b59dd8f59514bd54f620212352c0de55be..236a5d60649be6b46d65558f05a25082fd9cd12a 100644 (file)
@@ -153,7 +153,6 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
 {
        void    *d;
        unsigned *buf;
-//     byte    stackbuf[1024];         // avoid dirtying the cache heap
 
        if (!mod->needload)
        {
@@ -171,7 +170,6 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
 
 // load the file
        buf = (unsigned *)COM_LoadMallocFile (mod->name, false);
-//     buf = (unsigned *)COM_LoadStackFile (mod->name, stackbuf, sizeof(stackbuf), false);
        if (!buf)
        {
                if (crash)
@@ -205,7 +203,7 @@ model_t *Mod_LoadModel (model_t *mod, qboolean crash)
                Mod_LoadBrushModel (mod, buf);
                break;
        }
-       free(buf);
+       qfree(buf);
 
        return mod;
 }
index 1dde92119d17f4a799bb7cf6935c84e016935384..c1d63e523c07aef8b832bd2bd10659326b39bc52 100644 (file)
@@ -91,7 +91,7 @@ void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int framenum,
        {
                pspriteframe->gl_texturenum = GL_LoadTexture (name, width, height, (byte *)(pinframe + 1), true, true, bytesperpixel);
                // make fog version (just alpha)
-               pixbuf = pixel = malloc(width*height*4);
+               pixbuf = pixel = qmalloc(width*height*4);
                inpixel = (byte *)(pinframe + 1);
                if (bytesperpixel == 1)
                {
@@ -120,7 +120,7 @@ void * Mod_LoadSpriteFrame (void * pin, mspriteframe_t **ppframe, int framenum,
                }
                sprintf (name, "%s_%ifog", loadmodel->name, framenum);
                pspriteframe->gl_fogtexturenum = GL_LoadTexture (name, width, height, pixbuf, true, true, 4);
-               free(pixbuf);
+               qfree(pixbuf);
        }
 
        return (void *)((byte *)pinframe + sizeof (dspriteframe_t) + size);
index 60969b1478c22dbc339f3699a5c6c84c1e7ebd82..f43efcfc82a9b946bfe0f3bc2a83170c7da0283f 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -90,7 +90,7 @@ void Palette_Init()
        if (!pal)
                Sys_Error ("Couldn't load gfx/palette.lmp");
        memcpy(host_basepal, pal, 765);
-       free(pal);
+       qfree(pal);
        host_basepal[765] = host_basepal[766] = host_basepal[767] = 0; // LordHavoc: force the transparent color to black
        Palette_Setup8to24();
 //     Palette_Setup15to8();
index 678e95bddb07af5a3a5fac2e424e6185b8fb5787..03980806f05b15e5b94c259b082f4c19099b49d7 100644 (file)
--- a/r_part.c
+++ b/r_part.c
@@ -189,15 +189,15 @@ void R_InitParticleTexture (void)
 
 void r_part_start()
 {
-       particles = (particle_t *) malloc (r_numparticles * sizeof(particle_t));
-       freeparticles = (void *) malloc (r_numparticles * sizeof(particle_t *));
+       particles = (particle_t *) qmalloc(r_numparticles * sizeof(particle_t));
+       freeparticles = (void *) qmalloc(r_numparticles * sizeof(particle_t *));
        R_InitParticleTexture ();
 }
 
 void r_part_shutdown()
 {
-       free(particles);
-       free(freeparticles);
+       qfree(particles);
+       qfree(freeparticles);
 }
 
 /*
index 278d2eb4f78b79e097fb58e76b73fa21d908dd08..f573c370365e49061e35837322f9ab92175b2591 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -226,7 +226,6 @@ sfxcache_t *S_LoadSound (sfx_t *s)
        int             len;
        float   stepscale;
        sfxcache_t      *sc;
-       byte    stackbuf[1*1024];               // avoid dirtying the cache heap
 
 // see if still in memory
        sc = Cache_Check (&s->cache);
@@ -240,7 +239,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
 
 //     Con_Printf ("loading %s\n",namebuffer);
 
-       data = COM_LoadStackFile(namebuffer, stackbuf, sizeof(stackbuf), false);
+       data = COM_LoadMallocFile(namebuffer, false);
 
        if (!data)
        {
@@ -253,6 +252,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
        if (info.channels < 1 || info.channels > 2)
        {
                Con_Printf ("%s has an unsupported number of channels (%i)\n",s->name, info.channels);
+               qfree(data);
                return NULL;
        }
        /*
@@ -270,7 +270,10 @@ sfxcache_t *S_LoadSound (sfx_t *s)
 
        sc = Cache_Alloc ( &s->cache, len + sizeof(sfxcache_t), s->name);
        if (!sc)
+       {
+               qfree(data);
                return NULL;
+       }
        
        sc->length = info.samples;
        sc->loopstart = info.loopstart;
@@ -280,6 +283,7 @@ sfxcache_t *S_LoadSound (sfx_t *s)
 
        ResampleSfx (s, sc->speed, data + info.dataofs);
 
+       qfree(data);
        return sc;
 }
 
index 45c1e5dbafe15fe35b2cf2a82088b2936fbfd925..8095fa9bb4bafa1af5d198db2ea64daae15456fd 100644 (file)
@@ -416,7 +416,7 @@ int main (int c, char **v)
        j = COM_CheckParm("-mem");
        if (j)
                host_parms.memsize = (int) (atof(com_argv[j+1]) * 1024 * 1024);
-       host_parms.membase = malloc (host_parms.memsize);
+       host_parms.membase = qmalloc(host_parms.memsize);
        if (!host_parms.membase)
        {
                printf("Unable to allocate heap memory\n");
index d0f0d7930a6fc3786105185dfdf7a04633662122..574926260bc87247ccbab7611e68f4cd52376590 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -718,7 +718,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                        host_parms.memsize = atoi (com_argv[t]) * 1048576;
        }
 
-       host_parms.membase = malloc (host_parms.memsize);
+       host_parms.membase = qmalloc(host_parms.memsize);
 
        if (!host_parms.membase)
                Sys_Error ("Not enough memory free; check disk space\n");
index ec32703f922a963f4ed28d8f5552c7b9113fa60e..6703846f8276a168341f8159b7052af050c61e38 100644 (file)
@@ -269,7 +269,7 @@ int main (int argc, char **argv)
        memset (&host_parms, 0, sizeof(host_parms));
 
        host_parms.memsize = 16384*1024;
-       host_parms.membase = malloc (parms.memsize);
+       host_parms.membase = qmalloc(parms.memsize);
 
        _getcwd (cwd, sizeof(cwd));
        if (cwd[strlen(cwd)-1] == '\\')
diff --git a/wad.c b/wad.c
index 48c581144b4819a61c1db1d2296c89d2a2dd7ae8..64d35d82ce46f132a599ccc42d0b00371cf99b6f 100644 (file)
--- a/wad.c
+++ b/wad.c
@@ -206,7 +206,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
        infotableofs = LittleLong(header.infotableofs);
        if (fseek(file, infotableofs, SEEK_SET))
        {Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
-       if (!(lumps = malloc(sizeof(lumpinfo_t)*numlumps)))
+       if (!(lumps = qmalloc(sizeof(lumpinfo_t)*numlumps)))
        {Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
 
        if (fread(lumps, sizeof(lumpinfo_t), numlumps, file) != numlumps)
@@ -232,7 +232,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
                texwadlump[j].position = LittleLong(lump_p->filepos);
                texwadlump[j].size = LittleLong(lump_p->disksize);
        }
-       free(lumps);
+       qfree(lumps);
        // leaves the file open
 }
 
@@ -323,7 +323,7 @@ byte *W_GetTexture(char *name, int matchwidth, int matchheight)
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return FALSE;}
                                // allocate space for expanded image,
                                // and load incoming image into upper area (overwritten as it expands)
-                               if (!(data = outdata = malloc(image_width*image_height*4)))
+                               if (!(data = outdata = qmalloc(image_width*image_height*4)))
                                {Con_Printf("W_GetTexture: out of memory");return FALSE;}
                                indata = outdata + image_width*image_height*3;
                                datasize = image_width*image_height*85/64;