From ec5f3c59f4d39d9a6673a330accc337cd7475a42 Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Sun, 1 Feb 2026 16:37:06 +0000 Subject: [PATCH] Fixed some memory leaks --- as.h | 2 +- lib.c | 9 +++++++++ process.c | 21 +++++++++++++++------ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/as.h b/as.h index 7062ee7..944deec 100644 --- a/as.h +++ b/as.h @@ -50,7 +50,7 @@ struct as_state { char *ext; struct symbol *end_symbol; - int format; + int format, verbose; }; diff --git a/lib.c b/lib.c index ba12335..ef7f2e6 100644 --- a/lib.c +++ b/lib.c @@ -34,6 +34,7 @@ struct as_option { #define AS_OPTION_LISTING 5 #define AS_OPTION_OUTFILE 6 #define AS_OPTION_UNDEF 7 +#define AS_OPTION_VERBOSE 8 static struct as_option opts[] = { @@ -44,6 +45,7 @@ static struct as_option opts[] = { { "-f", AS_OPTION_FORMAT, AS_OPTION_HAS_ARG }, { "-l", AS_OPTION_LISTING, AS_OPTION_HAS_ARG }, { "-o", AS_OPTION_OUTFILE, AS_OPTION_HAS_ARG }, + { "-v", AS_OPTION_VERBOSE, AS_OPTION_NO_ARG }, { "--help", AS_OPTION_HELP, AS_OPTION_NO_ARG }, { 0, 0, 0 } @@ -496,6 +498,13 @@ void parse_args (int argc, char **argv, int optind) { } + case AS_OPTION_VERBOSE: { + + state->verbose++; + break; + + } + default: { report_at (program_name, 0, REPORT_ERROR, "unsupported option '%s'", r); diff --git a/process.c b/process.c index 15c9095..56d5c5e 100644 --- a/process.c +++ b/process.c @@ -137,6 +137,7 @@ static char *preprocess_line (char *src, int in_macro) { } + free (sname); continue; } @@ -144,11 +145,15 @@ static char *preprocess_line (char *src, int in_macro) { if (xstrcasecmp (sname, "DGROUP") == 0 && *caret == ':') { caret++; + + free (sname); continue; } cstr_cat (&cstr, start, caret - start); + + free (sname); continue; } @@ -1204,8 +1209,8 @@ void process_file (const char *ifile) { char *line, *line_end, *real_line; unsigned long real_line_len; + unsigned long new_line_number = 1; unsigned long newlines; - unsigned long new_line_number; struct pp_pseudo_op_entry *poe; void *load_line_internal_data = NULL; @@ -1231,7 +1236,6 @@ void process_file (const char *ifile) { } - new_line_number = 1; load_line_internal_data = load_line_create_internal_data (&new_line_number); while (!load_line (&line, &line_end, &real_line, &real_line_len, &newlines, fp, &load_line_internal_data)) { @@ -1247,6 +1251,11 @@ void process_file (const char *ifile) { } start = line; + + if (state->verbose) { + printf ("%s:%lu: %.*s", get_filename (), get_line_number (), (int) real_line_len, real_line); + } + caret = (line = skip_whitespace (line)); if (!ignore_line && line >= line_end) { @@ -1269,8 +1278,8 @@ void process_file (const char *ifile) { if ((poe = find_cond_directive (arg))) { poe->handler (start, &line); - free (arg); + free (arg); continue; } @@ -1280,8 +1289,8 @@ void process_file (const char *ifile) { if ((poe = find_directive (arg))) { poe->handler (start, &line); - free (arg); + free (arg); continue; } @@ -1317,6 +1326,8 @@ void process_file (const char *ifile) { continue; } + + free (arg); } @@ -1329,9 +1340,7 @@ void process_file (const char *ifile) { if (line < line_end) { char *tokenized_line = preprocess_line (line, 0); - process_line (tokenized_line, tokenized_line + strlen (tokenized_line)); - free (tokenized_line); } -- 2.34.1