From 4cf017bb6b26381d71aa07100bc21f7bdad43058 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sat, 18 Aug 2012 16:47:33 +0200 Subject: [PATCH] keep the filenames of all lexed files in a global lex_filenames vector because we don't strdup the filenames into lex_ctx, but copy the pointer --- lexer.c | 14 +++++++++++++- lexer.h | 1 + main.c | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lexer.c b/lexer.c index 9956e0f..d9483d8 100644 --- a/lexer.c +++ b/lexer.c @@ -9,6 +9,8 @@ MEM_VEC_FUNCTIONS(token, char, value) MEM_VEC_FUNCTIONS(lex_file, frame_macro, frames) +VECTOR_MAKE(char*, lex_filenames); + void lexerror(lex_file *lex, const char *fmt, ...) { va_list ap; @@ -145,9 +147,19 @@ lex_file* lex_open(const char *file) lex->peekpos = 0; + lex_filenames_add(lex->name); + return lex; } +void lex_cleanup(void) +{ + size_t i; + for (i = 0; i < lex_filenames_elements; ++i) + mem_d(lex_filenames_data[i]); + mem_d(lex_filenames_data); +} + void lex_close(lex_file *lex) { size_t i; @@ -162,7 +174,7 @@ void lex_close(lex_file *lex) fclose(lex->file); if (lex->tok) token_delete(lex->tok); - mem_d(lex->name); + /* mem_d(lex->name); collected in lex_filenames */ mem_d(lex); } diff --git a/lexer.h b/lexer.h index 5e0d18c..b3114ec 100644 --- a/lexer.h +++ b/lexer.h @@ -111,6 +111,7 @@ MEM_VECTOR_PROTO(lex_file, char, token); lex_file* lex_open (const char *file); void lex_close(lex_file *lex); int lex_do (lex_file *lex); +void lex_cleanup(void); /* Parser * diff --git a/main.c b/main.c index d354e3d..7369a9c 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ * SOFTWARE. */ #include "gmqcc.h" +#include "lexer.h" uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)]; @@ -475,6 +476,7 @@ cleanup: if (opts_output_free) mem_d((char*)opts_output); + lex_cleanup(); util_meminfo(); return retval; } -- 2.39.2