]> sourceware.org Git - systemtap.git/commitdiff
PR10260: Clean up all resources after init errors
authorJosh Stone <jistone@redhat.com>
Wed, 10 Jun 2009 22:50:04 +0000 (15:50 -0700)
committerJosh Stone <jistone@redhat.com>
Wed, 10 Jun 2009 22:50:04 +0000 (15:50 -0700)
When anything in systemtap_module_init fails, and we return non-zero,
then the module load is aborted.  The normal module unload path
(systemtap_module_exit) is not even attempted, so we need to make sure
that all partially-allocated resources are returned.

Our timer callbacks for the gettimeofday subsystem are a classic example
of this error.  If we don't unregister the timers before aborting init,
they will later be called and cause a kernel fault.

We also were neglecting to free the percpu context.  A memory leak is
less harmful, but that's fixed now too.

translate.cxx

index 4e312f3e63747f3559edd496ff3d2cb5e2ef1b8e..518e5584cdc35193ee7d50dc8a24d0f9e3ed2b37 100644 (file)
@@ -1249,6 +1249,14 @@ c_unparser::emit_module_init ()
   o->newline() << "synchronize_sched();";
   o->newline() << "#endif";
 
+  // In case gettimeofday was started, it needs to be stopped
+  o->newline() << "#ifdef STAP_NEED_GETTIMEOFDAY";
+  o->newline() << " _stp_kill_time();";  // An error is no cause to hurry...
+  o->newline() << "#endif";
+
+  // Free up the context memory after an error too
+  o->newline() << "free_percpu (contexts);";
+
   o->newline() << "return rc;";
   o->newline(-1) << "}\n";
 }
This page took 0.039411 seconds and 5 git commands to generate.