[ovs-dev] [PATCHv3 3/3] ovsdb-server.c: Fix memory leak

Yifeng Sun pkusunyifeng at gmail.com
Tue Oct 31 17:52:10 UTC 2017


Valgrind testcase 2349 (ovn -- DSCP marking check) reports the leak below:
21 bytes in 21 blocks are definitely lost in loss record 24 of 362
    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x436FD4: xmalloc (util.c:120)
    by 0x437044: xmemdup0 (util.c:150)
    by 0x408C97: add_manager_options (ovsdb-server.c:709)
    by 0x408C97: query_db_remotes (ovsdb-server.c:765)
    by 0x408C97: reconfigure_remotes (ovsdb-server.c:926)
    by 0x406273: main_loop (ovsdb-server.c:194)
    by 0x406273: main (ovsdb-server.c:434)

When options are freed, options->role need to be freed explicitly.

v1->v3: Amend valgrind report.

Signed-off-by: Yifeng Sun <pkusunyifeng at gmail.com>
---
 ovsdb/ovsdb-server.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 030d86ba467f..cd30dd48425b 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -674,6 +674,21 @@ add_remote(struct shash *remotes, const char *target)
     return options;
 }
 
+static void
+free_remotes(struct shash *remotes)
+{
+    struct ovsdb_jsonrpc_options *options;
+    struct shash_node *node;
+
+    if (remotes) {
+        SHASH_FOR_EACH(node, remotes) {
+            options = node->data;
+            free(options->role);
+        }
+        shash_destroy_free_data(remotes);
+    }
+}
+
 /* Adds a remote and options to 'remotes', based on the Manager table row in
  * 'row'. */
 static void
@@ -929,7 +944,7 @@ reconfigure_remotes(struct ovsdb_jsonrpc_server *jsonrpc,
         }
     }
     ovsdb_jsonrpc_server_set_remotes(jsonrpc, &resolved_remotes);
-    shash_destroy_free_data(&resolved_remotes);
+    free_remotes(&resolved_remotes);
 
     return errors.string;
 }
-- 
2.7.4



More information about the dev mailing list