From f2e166c5925fda49b5abeadc0aa0f9156b99cf11 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 21 Jun 2014 03:59:23 -0700 Subject: [PATCH] Fix varying levels of stupid memory errors. --- sourcepawn/compiler/sc1.c | 3 ++- sourcepawn/compiler/sc2.c | 26 +++++++++++++++++++++++++- sourcepawn/compiler/sctracker.c | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/sourcepawn/compiler/sc1.c b/sourcepawn/compiler/sc1.c index a8ecee688..1e4ebde52 100644 --- a/sourcepawn/compiler/sc1.c +++ b/sourcepawn/compiler/sc1.c @@ -3504,6 +3504,7 @@ methodmap_method_t *parse_method(methodmap_t *map) first_arg->hasdefault || first_arg->numtags != 1) { + free(method); error(108, spectype, map->name); return NULL; } @@ -3598,7 +3599,7 @@ static void domethodmap(LayoutSpec spec) needtoken(tTERM); - methods = (methodmap_method_t **)realloc(map->methods, sizeof(methodmap_method_t *) * map->nummethods); + methods = (methodmap_method_t **)realloc(map->methods, sizeof(methodmap_method_t *) * (map->nummethods + 1)); if (!methods) { error(123); return; diff --git a/sourcepawn/compiler/sc2.c b/sourcepawn/compiler/sc2.c index afa718286..fa28e6b1f 100644 --- a/sourcepawn/compiler/sc2.c +++ b/sourcepawn/compiler/sc2.c @@ -2612,6 +2612,29 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_ constvalue *stateptr; int mustdelete; + // Hack - proxies have a "target" pointer, but the target could be deleted + // already if done inside the main loop below. To get around this we do a + // precursor pass. Note that proxies can only be at the global scope. + if (origRoot == &glbtab) { + symbol *iter = root; + while (iter->next) { + sym = iter->next; + + if (sym->ident != iPROXY) { + iter = sym; + continue; + } + + if (delete_functions || (sym->target->usage & uNATIVE) != 0) { + RemoveFromHashTable(sp_Globals, sym); + iter->next = sym->next; + free_symbol(sym); + } else { + iter = sym; + } + } + } + /* erase only the symbols with a deeper nesting level than the * specified nesting level */ while (root->next!=NULL) { @@ -2655,7 +2678,8 @@ SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_ assert(sym->parent==NULL); break; case iPROXY: - mustdelete=delete_functions || (sym->target->usage & uNATIVE)!=0; + // Original loop determined it was okay to keep. + mustdelete=FALSE; break; case iARRAYCELL: case iARRAYCHAR: diff --git a/sourcepawn/compiler/sctracker.c b/sourcepawn/compiler/sctracker.c index cf3636f1e..85c7c0265 100644 --- a/sourcepawn/compiler/sctracker.c +++ b/sourcepawn/compiler/sctracker.c @@ -484,6 +484,8 @@ void methodmaps_free() methodmap_t *ptr = methodmap_first; while (ptr) { methodmap_t *next = ptr->next; + for (size_t i = 0; i < ptr->nummethods; i++) + free(ptr->methods[i]); free(ptr->methods); free(ptr); ptr = next;