diff options
author | Andy Zhou <azhou@ovn.org> | 2016-09-20 14:12:26 -0700 |
---|---|---|
committer | Andy Zhou <azhou@ovn.org> | 2016-09-27 10:44:33 -0700 |
commit | 5e8bc3c549ca9bfa02c5525c02cb4ee12ef1f06e (patch) | |
tree | dadbe104806cf7c5d380b16e9c3042b6281e19eb /ovsdb | |
parent | 20853442766babdcb2498b857d999b3dd0faacb1 (diff) | |
download | openvswitch-5e8bc3c549ca9bfa02c5525c02cb4ee12ef1f06e.tar.gz |
ovsdb: Fix memory leak when disposing 'replication_dbs'
Found by inspection.
The 'replication_dbs' structure was not freed after use.
Fix by adding a new function replication_dbs_destroy().
Also remove unnecessary global pointer variables initializer.
Signed-off-by: Andy Zhou <azhou@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'ovsdb')
-rw-r--r-- | ovsdb/replication.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/ovsdb/replication.c b/ovsdb/replication.c index 91b55856b..1c77b1876 100644 --- a/ovsdb/replication.c +++ b/ovsdb/replication.c @@ -38,7 +38,7 @@ VLOG_DEFINE_THIS_MODULE(replication); static char *sync_from; -static struct jsonrpc_session *session = NULL; +static struct jsonrpc_session *session; static unsigned int session_seqno = UINT_MAX; static struct jsonrpc_msg *create_monitor_request(struct ovsdb *db); @@ -101,9 +101,10 @@ static enum ovsdb_replication_state state; * in 'replication dbs', which is a subset of all dbs and remote dbs whose * schema matches. */ static struct shash local_dbs = SHASH_INITIALIZER(&local_dbs); -static struct shash *replication_dbs = NULL; +static struct shash *replication_dbs; static struct shash *replication_db_clone(struct shash *dbs); +static void replication_dbs_destroy(void); /* Find 'struct ovsdb' by name within 'replication_dbs' */ static struct ovsdb* find_db(const char *db_name); @@ -118,8 +119,7 @@ replication_init(const char *sync_from_, const char *exclude_tables) * parseable. An error here is unexpected. */ ovs_assert(!err); - shash_destroy(replication_dbs); - replication_dbs = NULL; + replication_dbs_destroy(); shash_clear(&local_dbs); if (session) { @@ -160,7 +160,7 @@ replication_run(void) request_ids_add(request->id, NULL); jsonrpc_session_send(session, request); - shash_destroy(replication_dbs); + replication_dbs_destroy(); replication_dbs = replication_db_clone(&local_dbs); state = RPL_S_DB_REQUESTED; @@ -464,8 +464,7 @@ replication_destroy(void) } request_ids_destroy(); - shash_destroy(replication_dbs); - replication_dbs = NULL; + replication_dbs_destroy(); shash_destroy(&local_dbs); } @@ -753,6 +752,14 @@ replication_db_clone(struct shash *dbs) return new; } +static void +replication_dbs_destroy(void) +{ + shash_destroy(replication_dbs); + free(replication_dbs); + replication_dbs = NULL; +} + /* Return true if replication just started or is ongoing. * Return false if the connection failed, or the replication * was not able to start. */ |