diff mbox

[ovs-dev] ovsdb: Fix memory leak when disposing 'replication_dbs'

Message ID 1474418987-54165-1-git-send-email-azhou@ovn.org
State Accepted
Headers show

Commit Message

Andy Zhou Sept. 21, 2016, 12:49 a.m. UTC
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>
---
 ovsdb/replication.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Comments

Ben Pfaff Sept. 27, 2016, 3:32 a.m. UTC | #1
On Tue, Sep 20, 2016 at 05:49:47PM -0700, Andy Zhou wrote:
> 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>
Andy Zhou Sept. 27, 2016, 6:03 p.m. UTC | #2
On Mon, Sep 26, 2016 at 8:32 PM, Ben Pfaff <blp@ovn.org> wrote:

> On Tue, Sep 20, 2016 at 05:49:47PM -0700, Andy Zhou wrote:
> > 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>
>

Thanks. Pushed to master and branch-2.6
diff mbox

Patch

diff --git a/ovsdb/replication.c b/ovsdb/replication.c
index 91b5585..1c77b18 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. */