Client: Fixed some warnings and some added some paranoid free() calls.

This commit is contained in:
Marco Cawthorne 2020-10-16 02:26:45 +02:00
parent 63d36cc677
commit f4ade524fe
9 changed files with 45 additions and 20 deletions

View file

@ -884,5 +884,7 @@ Incase you need to free something
void
CSQC_Shutdown(void)
{
Sentences_Shutdown();
Titles_Shutdown();
Sound_Shutdown();
}

View file

@ -77,6 +77,17 @@ typedef struct
var string g_sentences_samplepath;
void
Sentences_Shutdown(void)
{
#ifdef DYNAMIC_SENTENCES
if (g_sentences)
memfree(g_sentences);
#endif
g_sentences_count = 0;
}
void
Sentences_Init(void)
{
@ -84,15 +95,7 @@ Sentences_Init(void)
string temp;
int c, i;
if (g_sentences_count > 0) {
g_sentences_count = 0;
#ifndef DYNAMIC_SENTENCES
if (g_sentences) {
memfree(g_sentences);
}
#endif
}
Sentences_Shutdown();
fs_sentences = fopen("sound/sentences.txt", FILE_READ);
@ -117,7 +120,7 @@ Sentences_Init(void)
/* allocate memory and increase count */
#ifdef DYNAMIC_SENTENCES
g_sentences_count++;
g_sentences = memrealloc(g_sentences,
g_sentences = (sentences_t *)memrealloc(g_sentences,
sizeof(sentences_t),
x,
g_sentences_count);

View file

@ -57,6 +57,15 @@ Titles_ParseFunString(string temp)
return temp;
}
void
Titles_Shutdown(void)
{
if (g_titles)
memfree(g_titles);
g_titles_count = 0;
}
void
Titles_Init(void)
{
@ -77,6 +86,8 @@ Titles_Init(void)
int braced;
int id = 0;
Titles_Shutdown();
fs_titles = fopen("titles.txt", FILE_READ);
if (fs_titles < 0) {

View file

@ -232,7 +232,8 @@ func_tracktrain::Realign(void)
CBaseEntity first, second;
string strFirst, strSecond;
first = second = t = f = __NULL__;
first = second = __NULL__;
t = f = __NULL__;
for (f = world; (f = find(f, ::target, targetname));) {
/* we found the right entity */

View file

@ -430,7 +430,8 @@ func_vehicle::Realign(void)
CBaseEntity first, second;
string strFirst, strSecond;
first = second = t = f = __NULL__;
first = second = __NULL__;
t = f = __NULL__;
for (f = world; (f = find(f, ::target, targetname));) {
/* we found the right entity */

View file

@ -82,7 +82,7 @@ FMX_Init(void)
searchhandle list;
list = search_begin("plugins/chatsounds/*.txt", TRUE, TRUE);
for (int i = 0; i < search_getsize(list); i++) {
for (i = 0; i < search_getsize(list); i++) {
print(sprintf("Found %s\n", search_getfilename(list, i)));
}
search_end(list);

View file

@ -105,7 +105,7 @@ Node_Link(node_t *n1, node_t *n2)
}
int idx = n1->nb_count++;
n1->nb = memrealloc(n1->nb, sizeof(*n1->nb), idx, n1->nb_count);
n1->nb = (neighbour_s *)memrealloc(n1->nb, sizeof(*n1->nb), idx, n1->nb_count);
local struct neighbour_s *n = n1->nb+idx;
n->node = w2n;
n->dist = vlen(n2->origin - n1->origin);
@ -167,7 +167,7 @@ Nodes_Init(void)
/* run through the ents and rebuild the tree */
for (entity a = world; (a = find(a, ::classname, "info_node"));) {
int iID = g_iNodes++;
g_pNodes = memrealloc(g_pNodes, sizeof(node_t), iID, g_iNodes);
g_pNodes = (node_t *)memrealloc(g_pNodes, sizeof(node_t), iID, g_iNodes);
node_t *n = g_pNodes + iID;
n->origin = a.origin;
n->nb = __NULL__;

View file

@ -64,7 +64,7 @@ Sentences_Init(void)
/* allocate memory and increase count */
#ifdef DYNAMIC_SENTENCES
g_sentences_count++;
g_sentences = memrealloc(g_sentences,
g_sentences = (string *)memrealloc(g_sentences,
sizeof(string),
x,
g_sentences_count);

View file

@ -17,8 +17,8 @@
.float maxspeed;
.float flags;
/* make sure it's all reset */
void Sound_Init(void)
void
Sound_Shutdown(void)
{
if (g_sounds) {
memfree(g_sounds);
@ -28,6 +28,13 @@ void Sound_Init(void)
g_hashsounds = 0;
}
void
Sound_Init(void)
{
/* make sure it's all reset */
Sound_Shutdown();
}
void
Sound_ParseField(int i, int a)
{
@ -224,7 +231,7 @@ Sound_Precache(string shader)
}
g_sounds_count++;
g_sounds = memrealloc(g_sounds, sizeof(snd_t), index, g_sounds_count);
g_sounds = (snd_t *)memrealloc(g_sounds, sizeof(snd_t), index, g_sounds_count);
g_sounds[index].volume = 1.0f;
g_sounds[index].dist_max = 1;