[ovs-dev] [PATCH 5/5] ovs-vswitchd: Avoid or suppress memory leak warning for glibc aio.

Ben Pfaff blp at ovn.org
Thu Jan 25 23:39:49 UTC 2018


The asynchronous IO library in glibc starts threads that show up as memory
leaks in valgrind.  This commit attempts to avoid the warnings by flushing
all the asynchronous I/O to the log file before exiting.  This only does
part of the job for glibc since it keeps the threads around for some
undefined idle time before killing them, so in addition this commit adds a
valgrind suppression to stop displaying these warnings in any case.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 include/openvswitch/vlog.h |  1 +
 lib/vlog.c                 | 10 ++++++++++
 tests/glibc.supp           |  9 +++++++++
 vswitchd/ovs-vswitchd.c    |  1 +
 4 files changed, 21 insertions(+)

diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h
index 3a4042113a36..98d477911acc 100644
--- a/include/openvswitch/vlog.h
+++ b/include/openvswitch/vlog.h
@@ -146,6 +146,7 @@ void vlog_set_syslog_target(const char *target);
 /* Initialization. */
 void vlog_init(void);
 void vlog_enable_async(void);
+void vlog_disable_async(void);
 
 /* Functions for actual logging. */
 void vlog(const struct vlog_module *, enum vlog_level, const char *format, ...)
diff --git a/lib/vlog.c b/lib/vlog.c
index 6e87665fcd11..f286950431ff 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -836,6 +836,16 @@ vlog_enable_async(void)
     ovs_mutex_unlock(&log_file_mutex);
 }
 
+void
+vlog_disable_async(void)
+{
+    ovs_mutex_lock(&log_file_mutex);
+    log_async = false;
+    async_append_destroy(log_writer);
+    log_writer = NULL;
+    ovs_mutex_unlock(&log_file_mutex);
+}
+
 /* Print the current logging level for each module. */
 char *
 vlog_get_levels(void)
diff --git a/tests/glibc.supp b/tests/glibc.supp
index 948ee013f458..031f8bde0f77 100644
--- a/tests/glibc.supp
+++ b/tests/glibc.supp
@@ -15,3 +15,12 @@
    fun:set_up_timer
 }
 
+{
+   aio
+   Memcheck:Leak
+   fun:calloc
+   ...
+   fun:allocate_stack
+   ...
+   fun:__aio_create_helper_thread
+}
diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c
index 53e511999594..12cb5d494d41 100644
--- a/vswitchd/ovs-vswitchd.c
+++ b/vswitchd/ovs-vswitchd.c
@@ -136,6 +136,7 @@ main(int argc, char *argv[])
     bridge_exit(cleanup);
     unixctl_server_destroy(unixctl);
     service_stop();
+    vlog_disable_async();
     ovsrcu_exit();
 
     return 0;
-- 
2.10.2



More information about the dev mailing list