Fixed bad free on stack.

Still need to figure that one out.
This commit is contained in:
Jacob Signorovitch 2025-05-07 08:54:19 -04:00
parent 7b99292547
commit 743d16f696
3 changed files with 6 additions and 13 deletions

View File

@ -7,12 +7,13 @@
#include <string.h>
HTab* htab_init() {
HTab* htab = calloc(1, sizeof(HTab));
HTab* htab = malloc(sizeof(HTab));
return htab;
}
void htab_destroy(HTab* htab) { free(htab); }
void htab_destroy(HTab* htab) { // free(htab);
}
// Get the index of a key.
size_t geti(char* key) {

View File

@ -4,10 +4,8 @@
#include "include/ast.h"
#include "include/dstr.h"
#include "include/exec.h"
#include "include/global.h"
#include "include/htab.h"
#include "include/lexer.h"
#include "include/stack.h"
#include "include/util.h"
#include "../build/grammars/grammar.tab.h"
@ -17,16 +15,11 @@ extern AST* root;
extern char* inp;
extern int yyparse();
Stack* scope;
int main(int argc, char** argv) {
if (argc - 1 && strlen(argv[1]) > 0 && (inp = argv[1]) && !yyparse()) {
log_dbg("Parsed successfully!\n");
ast_print(exec_start(root));
HTab* global = stack_pop(scope);
htab_destroy(global);
stack_destroy(scope);
ast_destroy(root);
exit(0);
}
@ -63,9 +56,6 @@ int main(int argc, char** argv) {
#endif
ast_print(exec_start(root));
HTab* global = stack_pop(scope);
htab_destroy(global);
stack_destroy(scope);
ast_destroy(root);
}

View File

@ -12,12 +12,14 @@ Scope* scope_init(Scope* inherit) {
}
void scope_destroy(Scope* scope) {
if (!scope) return;
htab_destroy(scope->here);
if (scope->inherit != NULL) scope_destroy(scope->inherit);
free(scope);
}
void scope_destroy_psv(Scope* scope) {
if (!scope) return;
htab_destroy(scope->here);
scope->inherit = NULL;
free(scope);