ovsdb-server: Free memory on exit.
authorBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 22:41:00 +0000 (14:41 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 23:21:09 +0000 (15:21 -0800)
It is not really important to free memory on program exit, but it makes it
easier to see real memory leaks.

Found with valgrind.

ovsdb/jsonrpc-server.c
ovsdb/jsonrpc-server.h
ovsdb/ovsdb-server.c

index 6f2a656e59c920f9f1041f2d08b2289b7579f129..936dd1db37263325b527b55c88769b129ae09049 100644 (file)
@@ -100,6 +100,18 @@ ovsdb_jsonrpc_server_create(struct ovsdb *db)
     return server;
 }
 
+void
+ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
+{
+    struct shash_node *node, *next;
+
+    SHASH_FOR_EACH_SAFE (node, next, &svr->remotes) {
+        ovsdb_jsonrpc_server_del_remote(node);
+    }
+    shash_destroy(&svr->remotes);
+    free(svr);
+}
+
 /* Sets 'svr''s current set of remotes to the names in 'new_remotes'.  The data
  * values in 'new_remotes' are ignored.
  *
index b6f837d5e23be1aa6f9c322e9e7640e8ab6ab270..6c4acd7f349db7060d9766c94fbb5f60bfa68af4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ struct ovsdb;
 struct shash;
 
 struct ovsdb_jsonrpc_server *ovsdb_jsonrpc_server_create(struct ovsdb *);
+void ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *);
 
 void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
                                       const struct shash *);
index 900f4eccb1e63e58650cc2ec214b1d9b41a7513c..ab7e6c34895426c5dba56c5f0c5d658deec5da32 100644 (file)
@@ -112,6 +112,10 @@ main(int argc, char *argv[])
         ovsdb_trigger_wait(db, time_msec());
         poll_block();
     }
+    ovsdb_jsonrpc_server_destroy(jsonrpc);
+    ovsdb_destroy(db);
+    shash_destroy(&remotes);
+    unixctl_server_destroy(unixctl);
 
     return 0;
 }