]> granicus.if.org Git - yasm/commitdiff
Delayed destruction of arguments list until cpp_preproc_destroy() in cpp module.
authorpaulbarker <paulbarker@localhost>
Mon, 10 Sep 2007 10:17:19 +0000 (10:17 -0000)
committerpaulbarker <paulbarker@localhost>
Mon, 10 Sep 2007 10:17:19 +0000 (10:17 -0000)
svn path=/branches/multiarch/; revision=1940

modules/preprocs/cpp/cpp-preproc.c

index a35b2544994d2b32e10e420f1b62354d85fbe3a1..ec0a3d6dae02d1991a8471cb114f40a1028450d8 100644 (file)
@@ -111,11 +111,6 @@ cpp_build_cmdline(yasm_preproc_cpp *pp)
         APPEND(arg->op);
         APPEND(" ");
         APPEND(arg->param);
-
-        /* Remove this element from the list and free it. */
-        TAILQ_REMOVE(&pp->cpp_args, arg, entry);
-        yasm_xfree(arg->param);
-        yasm_xfree(arg);
     }
 
     /* Append final arguments. */
@@ -133,11 +128,6 @@ cpp_invoke(yasm_preproc_cpp *pp)
 
     cmdline = cpp_build_cmdline(pp);
 
-#if 0
-    /* Print the command line before executing. */
-    printf("%s\n", cmdline);
-#endif
-
     pp->f = popen(cmdline, "r");
     if (!pp->f)
         yasm__fatal( N_("Failed to execute preprocessor") );
@@ -145,6 +135,19 @@ cpp_invoke(yasm_preproc_cpp *pp)
     yasm_xfree(cmdline);
 }
 
+/* Free memory used by the list of arguments. */
+static void
+cpp_destroy_args(yasm_preproc_cpp *pp)
+{
+    cpp_arg_entry *arg;
+
+    while ( (arg = TAILQ_FIRST(&pp->cpp_args)) ) {
+        TAILQ_REMOVE(&pp->cpp_args, arg, entry);
+        yasm_xfree(arg->param);
+        yasm_xfree(arg);
+    }
+}
+
 /*******************************************************************************
     Interface functions.
 *******************************************************************************/
@@ -175,6 +178,8 @@ cpp_preproc_destroy(yasm_preproc *preproc)
             yasm__fatal( N_("Preprocessor exited with failure") );
     }
 
+    cpp_destroy_args(pp);
+
     yasm_xfree(pp->filename);
     yasm_xfree(pp);
 }