https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93019

--- Comment #6 from Costas Argyris <costas.argyris at gmail dot com> ---
Part of this may be because the driver::finalize function introduced here:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=9376dd63e6a2d94823f6faf8212c9f37bef5a656

is not called from main:

 int
 main (int argc, char **argv)
 {
-  driver d;
+  driver d (false, /* can_finalize */
+           false); /* debug */

   return d.main (argc, argv);
 }

It only gets called from the jit code it was designed to serve:

+void
+playback::context::
+invoke_embedded_driver (const vec <char *> *argvec)
+{
+  JIT_LOG_SCOPE (get_logger ());
+  driver d (true, /* can_finalize */
+           false); /* debug */
+  int result = d.main (argvec->length (),
+                      const_cast <char **> (argvec->address ()));
+  d.finalize ();
+  if (result)
+    add_error (NULL, "error invoking gcc driver");
+}

What is confusing to me though is that the can_finalize argument to the driver
constructor really seems to be referring only to the environment manager
env_manager component, not the entire driver.    driver::finalize does a lot
more than just call env.restore (), including freeing allocated memory.

I don't see why the inability to call env_manager::restore () should block
anyone from calling driver::finalize (), as the latter starts from env.restore
() but does a lot more later.    In other words, what does environment variable
management have to do with memory management and why is it allowed to block it?
   Can't these two be done independently?

Simply adding a call to driver::finalize in main:

 int
 main (int argc, char **argv)
 {
-  driver d (false, /* can_finalize */
+  driver d (true, /* can_finalize */
            false); /* debug */

-  return d.main (argc, argv);
+  int result = d.main (argc, argv);
+  d.finalize ();
+  return result;
 }


decreases the number of valgrind loss records from 95 to 62.

If can_finalize must stay false in main for whatever reason, then
driver::finalize could simply check if it can call env.restore such that it is
always possible to call driver::finalize regardless of what was passed for
can_finalize, and leave only env_manager::restore depend on that argument, as
it seems to be the only thing that is really relying on it (that would only
require an extra public method on env_manager to get the can_finalize value
that was passed - it is called m_can_restore in the class).

Reply via email to