From 9842ecc109d38eed8bb547787657d2099ae2f999 Mon Sep 17 00:00:00 2001
From: molivier <molivier@d7cf8633-e32d-0410-b094-e92efae38249>
Date: Fri, 2 Apr 2004 07:08:54 +0000
Subject: [PATCH] Replaced a direct call to "malloc" and "free", and removed
 several misuses of "Z_Malloc" where using the temp mempool was sufficient.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4075 d7cf8633-e32d-0410-b094-e92efae38249
---
 cl_particles.c |  4 ++--
 cmd.c          | 36 ++++++++++++++----------------------
 fs.c           |  4 ++--
 3 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/cl_particles.c b/cl_particles.c
index 790abe05..18ad1fc5 100644
--- a/cl_particles.c
+++ b/cl_particles.c
@@ -88,7 +88,7 @@ void fractalnoise(qbyte *noise, int size, int startgrid)
 	startgrid = bound(0, startgrid, size);
 
 	amplitude = 0xFFFF; // this gets halved before use
-	noisebuf = malloc(size*size*sizeof(int));
+	noisebuf = Mem_Alloc (tempmempool, size * size * sizeof (*noisebuf));
 	memset(noisebuf, 0, size*size*sizeof(int));
 
 	for (g2 = startgrid;g2;g2 >>= 1)
@@ -130,7 +130,7 @@ void fractalnoise(qbyte *noise, int size, int startgrid)
 	for (y = 0;y < size;y++)
 		for (x = 0;x < size;x++)
 			*noise++ = (qbyte) (((n(x,y) - min) * 256) / max);
-	free(noisebuf);
+	Mem_Free (noisebuf);
 #undef n
 }
 void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up)
diff --git a/cmd.c b/cmd.c
index acba1396..2e134d78 100644
--- a/cmd.c
+++ b/cmd.c
@@ -115,25 +115,25 @@ void Cbuf_InsertText (const char *text)
 	char	*temp;
 	int		templen;
 
-// copy off any commands still remaining in the exec buffer
+	// copy off any commands still remaining in the exec buffer
 	templen = cmd_text.cursize;
 	if (templen)
 	{
-		temp = Z_Malloc (templen);
+		temp = Mem_Alloc (tempmempool, templen);
 		memcpy (temp, cmd_text.data, templen);
 		SZ_Clear (&cmd_text);
 	}
 	else
-		temp = NULL;	// shut up compiler
+		temp = NULL;
 
-// add the entire text of the file
+	// add the entire text of the file
 	Cbuf_AddText (text);
 
-// add the copied off data
-	if (templen)
+	// add the copied off data
+	if (temp != NULL)
 	{
 		SZ_Write (&cmd_text, temp, templen);
-		Z_Free (temp);
+		Mem_Free (temp);
 	}
 }
 
@@ -237,7 +237,7 @@ void Cmd_StuffCmds_f (void)
 	if (!s)
 		return;
 
-	text = Z_Malloc (s+1);
+	text = Mem_Alloc (tempmempool, s + 1);
 	text[0] = 0;
 	for (i=1 ; i<com_argc ; i++)
 	{
@@ -248,8 +248,8 @@ void Cmd_StuffCmds_f (void)
 			strcat (text, " ");
 	}
 
-// pull out the commands
-	build = Z_Malloc (s+1);
+	// pull out the commands
+	build = Mem_Alloc (tempmempool, s + 1);
 	build[0] = 0;
 
 	for (i=0 ; i<s-1 ; i++)
@@ -274,8 +274,8 @@ void Cmd_StuffCmds_f (void)
 	if (build[0])
 		Cbuf_InsertText (build);
 
-	Z_Free (text);
-	Z_Free (build);
+	Mem_Free (text);
+	Mem_Free (build);
 }
 
 
@@ -330,15 +330,6 @@ Cmd_Alias_f
 Creates a new command that executes a command string (possibly ; seperated)
 ===============
 */
-static char *CopyString (char *in)
-{
-	char *out;
-
-	out = Z_Malloc (strlen(in)+1);
-	strcpy (out, in);
-	return out;
-}
-
 static void Cmd_Alias_f (void)
 {
 	cmdalias_t	*a;
@@ -390,7 +381,8 @@ static void Cmd_Alias_f (void)
 	}
 	strlcat (cmd, "\n", sizeof (cmd));
 
-	a->value = CopyString (cmd);
+	a->value = Z_Malloc (strlen (cmd) + 1);
+	strcpy (a->value, cmd);
 }
 
 /*
diff --git a/fs.c b/fs.c
index 90ba0702..e180f13d 100644
--- a/fs.c
+++ b/fs.c
@@ -1900,7 +1900,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 	if (separator < colon)
 		separator = colon;
 	basepathlength = separator - pattern;
-	basepath = Z_Malloc(basepathlength + 1);
+	basepath = Mem_Alloc (tempmempool, basepathlength + 1);
 	if (basepathlength)
 		memcpy(basepath, pattern, basepathlength);
 	basepath[basepathlength] = 0;
@@ -2004,7 +2004,7 @@ fssearch_t *FS_Search(const char *pattern, int caseinsensitive, int quiet)
 			stringlistfree(liststart);
 	}
 
-	Z_Free(basepath);
+	Mem_Free(basepath);
 	return search;
 }
 
-- 
2.39.5