[ovs-dev] [PATCH 1/1] vlog: fix memory leak in vlog_set_log_file() function

Damijan Skvarc damjan.skvarc at gmail.com
Wed Oct 2 11:44:49 UTC 2019


memory leak happens in case previously closed log file was reopened again,
for example:

ovs-appctl vlog/close
ovs-appctl vlog/reopen

memory leak is reported by valgrind in a form:

==4463== 76 bytes in 1 blocks are definitely lost in loss record 322 of 344
==4463==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4463==    by 0x534314: xmalloc (util.c:138)
==4463==    by 0x534384: xmemdup0 (util.c:168)
==4463==    by 0x53ACB9: vlog_set_log_file (vlog.c:403)
==4463==    by 0x53AEDC: vlog_reopen_log_file (vlog.c:434)
==4463==    by 0x53AF22: vlog_unixctl_reopen (vlog.c:683)
==4463==    by 0x533730: process_command (unixctl.c:308)
==4463==    by 0x533730: run_connection (unixctl.c:342)
==4463==    by 0x533730: unixctl_server_run (unixctl.c:393)
==4463==    by 0x4073AE: main (ovs-vswitchd.c:128)

Signed-off-by: Damijan Skvarc <damjan.skvarc at gmail.com>
---
 lib/vlog.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/vlog.c b/lib/vlog.c
index 01cfdc5..278b01c 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -395,11 +395,14 @@ vlog_set_log_file(const char *file_name)
     /* Close old log file, if any, and install new one. */
     ovs_mutex_lock(&log_file_mutex);
     if (log_fd >= 0) {
-        free(log_file_name);
         close(log_fd);
         async_append_destroy(log_writer);
     }
 
+    if (log_file_name) {
+        free(log_file_name);
+    }
+
     log_file_name = xstrdup(new_log_file_name);
     log_fd = new_log_fd;
     if (log_async) {
-- 
2.7.4



More information about the dev mailing list