Fixed some memory leaks master
authorRobert Pengelly <robertapengelly@hotmail.com>
Sun, 1 Feb 2026 16:37:06 +0000 (16:37 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Sun, 1 Feb 2026 16:37:06 +0000 (16:37 +0000)
as.h
lib.c
process.c

diff --git a/as.h b/as.h
index 7062ee79d789a99ffee3903e57942ea280c07cc2..944deec05b7d7f7ab0f9e99fe93398f012957917 100644 (file)
--- a/as.h
+++ b/as.h
@@ -50,7 +50,7 @@ struct as_state {
     char *ext;
     
     struct symbol *end_symbol;
     char *ext;
     
     struct symbol *end_symbol;
-    int format;
+    int format, verbose;
 
 };
 
 
 };
 
diff --git a/lib.c b/lib.c
index ba12335cae4df0f62610d8a603fc313f1c2b7622..ef7f2e6bc330f8e672ee34fb88dcef9de22cc005 100644 (file)
--- 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_LISTING           5
 #define     AS_OPTION_OUTFILE           6
 #define     AS_OPTION_UNDEF             7
+#define     AS_OPTION_VERBOSE           8
 
 static struct as_option opts[] = {
 
 
 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   },
     {   "-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                   }
     
     {   "--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);
             default: {
             
                 report_at (program_name, 0, REPORT_ERROR, "unsupported option '%s'", r);
index 15c909563ff61fb09bfe7410acbf4601686b79f9..56d5c5e4a52a5855e2984adac413986edc6d5f4e 100644 (file)
--- a/process.c
+++ b/process.c
@@ -137,6 +137,7 @@ static char *preprocess_line (char *src, int in_macro) {
                 
                 }
                 
                 
                 }
                 
+                free (sname);
                 continue;
             
             }
                 continue;
             
             }
@@ -144,11 +145,15 @@ static char *preprocess_line (char *src, int in_macro) {
             if (xstrcasecmp (sname, "DGROUP") == 0 && *caret == ':') {
             
                 caret++;
             if (xstrcasecmp (sname, "DGROUP") == 0 && *caret == ':') {
             
                 caret++;
+                
+                free (sname);
                 continue;
             
             }
             
             cstr_cat (&cstr, start, caret - start);
                 continue;
             
             }
             
             cstr_cat (&cstr, start, caret - start);
+            
+            free (sname);
             continue;
         
         }
             continue;
         
         }
@@ -1204,8 +1209,8 @@ void process_file (const char *ifile) {
     char *line, *line_end, *real_line;
     unsigned long real_line_len;
     
     char *line, *line_end, *real_line;
     unsigned long real_line_len;
     
+    unsigned long new_line_number = 1;
     unsigned long newlines;
     unsigned long newlines;
-    unsigned long new_line_number;
     
     struct pp_pseudo_op_entry *poe;
     void *load_line_internal_data = NULL;
     
     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)) {
     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;
         }
         
         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) {
         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);
                 if ((poe = find_cond_directive (arg))) {
                 
                     poe->handler (start, &line);
-                    free (arg);
                     
                     
+                    free (arg);
                     continue;
                 
                 }
                     continue;
                 
                 }
@@ -1280,8 +1289,8 @@ void process_file (const char *ifile) {
                     if ((poe = find_directive (arg))) {
                     
                         poe->handler (start, &line);
                     if ((poe = find_directive (arg))) {
                     
                         poe->handler (start, &line);
-                        free (arg);
                         
                         
+                        free (arg);
                         continue;
                     
                     }
                         continue;
                     
                     }
@@ -1317,6 +1326,8 @@ void process_file (const char *ifile) {
                     continue;
                 
                 }
                     continue;
                 
                 }
+                
+                free (arg);
             
             }
             
             
             }
             
@@ -1329,9 +1340,7 @@ void process_file (const char *ifile) {
             if (line < line_end) {
             
                 char *tokenized_line = preprocess_line (line, 0);
             if (line < line_end) {
             
                 char *tokenized_line = preprocess_line (line, 0);
-                
                 process_line (tokenized_line, tokenized_line + strlen (tokenized_line));
                 process_line (tokenized_line, tokenized_line + strlen (tokenized_line));
-                free (tokenized_line);
             
             }
         
             
             }