Nuke PR_GarbageCollect as it's both redundant with the new temp strings

and wrong anyway (could free strings it wasn't supposed to).

Don't free the string pointed to by a strref since it's already been
implicity freed (whole memory space nuked). Fixes new map crash.
This commit is contained in:
Bill Currie 2004-01-04 02:03:30 +00:00
parent 043c1ce466
commit a533761770
4 changed files with 4 additions and 68 deletions

View file

@ -227,7 +227,6 @@ int PR_SetTempString(progs_t *pr, const char *s);
int PR_NewString (progs_t *pr);
void PR_FreeString (progs_t *pr, int str);
void PR_FreeTempStrings (progs_t *pr);
void PR_GarbageCollect (progs_t *pr);
//
// PR Resources stuff

View file

@ -137,9 +137,12 @@ strref_free (void *_sr, void *_pr)
progs_t *pr = (progs_t*)_pr;
strref_t *sr = (strref_t*)_sr;
// Since this is only ever called by Hash_FlushTable, the memory pointed
// to by sr->string or sr->dstring has already been lost in the progs
// load/reload and thus there's no need to free it.
// free the string and ref only if it's not a static string
if (sr < pr->static_strings || sr >= pr->static_strings + pr->num_strings) {
PR_Zone_Free (pr, sr->string);
free_string_ref (pr, sr);
}
}
@ -188,53 +191,6 @@ PR_LoadStrings (progs_t *pr)
return 1;
}
void
PR_GarbageCollect (progs_t *pr)
{
const char *str;
unsigned int i;
int j;
ddef_t *def;
strref_t *sr;
for (i = 0; i < pr->dyn_str_size; i++)
for (j = 0; j < 1024; j++)
pr->dynamic_strings[i][j].count = 0;
for (i = 0; i < pr->progs->numglobaldefs; i++) {
def = &pr->pr_globaldefs[i];
if ((def->type & ~DEF_SAVEGLOBAL) == ev_string) {
str = G_GSTRING (pr, def->ofs);
if (str) {
sr = Hash_Find (pr->strref_hash, str);
if (sr)
sr->count++;
}
}
}
for (i = 0; i < pr->progs->numfielddefs; i++) {
def = &pr->pr_fielddefs[i];
if ((def->type & ~DEF_SAVEGLOBAL) == ev_string) {
for (j = 0; j < *pr->num_edicts; j++) {
str = E_GSTRING (pr, EDICT_NUM (pr, j), def->ofs);
if (str) {
sr = Hash_Find (pr->strref_hash, str);
if (sr)
sr->count++;
}
}
}
}
for (i = 0; i < pr->dyn_str_size; i++) {
for (j = 0; j < 1024; j++) {
sr = &pr->dynamic_strings[i][j];
if (sr->string && !sr->count) {
Hash_Del (pr->strref_hash, sr->string);
strref_free (sr, pr);
}
}
}
}
static inline strref_t *
get_strref (progs_t *pr, int num)
{

View file

@ -1901,18 +1901,6 @@ SV_CheckVars (void)
static void
SV_GarbageCollect (void)
{
if (pr_gc->int_val == 1
|| (pr_gc->int_val == 2 && sv_pr_state.progs->version == PROG_VERSION)) {
pr_gc_count++;
if (pr_gc_count >= pr_gc_interval->int_val) {
pr_gc_count = 0;
PR_GarbageCollect (&sv_pr_state);
}
} else {
// Make sure the count gets reset if the gc is disabled. I
// could use a callback, but I'm lazy
pr_gc_count = 0;
}
Object_Garbage_Collect ();
}

View file

@ -55,12 +55,6 @@ bi_print (progs_t *pr)
fprintf (stdout, "%s", str);
}
static void
bi_GarbageCollect (progs_t *pr)
{
PR_GarbageCollect (pr);
}
static void
bi_errno (progs_t *pr)
{
@ -183,7 +177,6 @@ void
BI_Init (progs_t *pr)
{
PR_AddBuiltin (pr, "print", bi_print, 1);
PR_AddBuiltin (pr, "GarbageCollect", bi_GarbageCollect, 2);
PR_AddBuiltin (pr, "errno", bi_errno, 3);
PR_AddBuiltin (pr, "strerror", bi_strerror, 4);
PR_AddBuiltin (pr, "open", bi_open, 5);