Skip to content

Commit

Permalink
ovsdb: Fix memory leak when disposing 'replication_dbs'
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed Sep 27, 2016
1 parent 2085344 commit 5e8bc3c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions ovsdb/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -464,8 +464,7 @@ replication_destroy(void)
}

request_ids_destroy();
shash_destroy(replication_dbs);
replication_dbs = NULL;
replication_dbs_destroy();

shash_destroy(&local_dbs);
}
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 5e8bc3c

Please sign in to comment.