From 23935e8bcb5be3e82ed2fb16333fdbea36eedfcd Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 2 Feb 2010 14:41:00 -0800 Subject: [PATCH] ovsdb-server: Free memory on exit. 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 | 12 ++++++++++++ ovsdb/jsonrpc-server.h | 3 ++- ovsdb/ovsdb-server.c | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 6f2a656e..936dd1db 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -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. * diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h index b6f837d5..6c4acd7f 100644 --- a/ovsdb/jsonrpc-server.h +++ b/ovsdb/jsonrpc-server.h @@ -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 *); diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 900f4ecc..ab7e6c34 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -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; } -- 2.30.2