michaelcp / skipfish

Automatically exported from code.google.com/p/skipfish
Apache License 2.0
0 stars 0 forks source link

Scrub out useless valgrind spewage. #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

These calls get rid of most of the annoying valgrind warnings
about unreleased memory from OpenSSL and your spiffy
memory allocator.

If you don't use valgrind, the patch fixes nothing that
program exit doesn't fix.

Whether you wish MALLOC_CHECK_ set (or not) is up to you.
I'm _NOT_ seeing false positives by removing the unsetenv().
OTOH, I'm still just running toy tests, getting there.

Index: skipfish.c
===================================================================
RCS file: /v/rpm/cvs/skipfish/skipfish.c,v
retrieving revision 1.1.1.1
diff -p -u -w -r1.1.1.1 skipfish.c
--- skipfish.c  4 Jul 2010 19:53:32 -0000   1.1.1.1
+++ skipfish.c  5 Jul 2010 01:27:30 -0000
@@ -151,8 +151,6 @@ int main(int argc, char** argv) {
   struct timeval tv;
   u64 st_time, en_time;

-  unsetenv("MALLOC_CHECK_");
-
   signal(SIGINT, ctrlc_handler);
   signal(SIGWINCH, resize_handler);
   signal(SIGPIPE, SIG_IGN);
@@ -510,14 +508,28 @@ int main(int argc, char** argv) {

   SAY(cLGN "[+] " cBRI "This was a great day for science!" cRST "\n\n");

-#ifdef DEBUG_ALLOCATOR
   if (!stop_soon) {
     destroy_database();
     destroy_http();
     destroy_signatures();
+#ifdef DEBUG_ALLOCATOR
     __AD_report();
-  }
 #endif /* DEBUG_ALLOCATOR */
+  }
+
+  ERR_clear_error();
+  ERR_remove_state(0);
+  ERR_remove_thread_state(NULL);
+  ERR_free_strings();
+  RAND_cleanup();
+  ENGINE_cleanup();
+  EVP_cleanup();
+  OBJ_cleanup();
+  X509V3_EXT_cleanup();
+  CONF_modules_finish();
+  CONF_modules_free();
+  CONF_modules_unload(1);
+  CRYPTO_cleanup_all_ex_data();

   fflush(0);

Original issue reported on code.google.com by n3npq....@gmail.com on 5 Jul 2010 at 1:36

GoogleCodeExporter commented 9 years ago
Ok, but are all of these actually needed? E.g., looks like ERR_remove_state and 
ERR_remove_thread_state do the same thing; any chance you can narrow down the 
list to what's actually necessary to keep Valgrind happy?

Also note that the built-in allocator does memory leak detection for all 
internal allocations already (and reports them in debug mode).

Original comment by lcam...@google.com on 5 Jul 2010 at 3:40

GoogleCodeExporter commented 9 years ago
Likely not all are needed, its my genetic fix-it-up fro OpenSSL
valgrind spewage. I''l reduce to minimum necessary and get back to you ...

Original comment by n3npq....@gmail.com on 5 Jul 2010 at 3:54

GoogleCodeExporter commented 9 years ago
The minimum cleanup necessary to remove valgrind spewage for OpenSSL 1.0.0 is

  EVP_cleanup();
  CRYPTO_cleanup_all_ex_data();

The EVP_cleanup() is THE most important if you have to choose just one call.

Original comment by n3npq....@gmail.com on 5 Jul 2010 at 1:14

GoogleCodeExporter commented 9 years ago
Added, thanks.

Original comment by lcam...@gmail.com on 5 Jul 2010 at 6:36