diff mbox series

[ovs-dev] ovsdb-server: Fix memleak when failing to rea storage.

Message ID 20210714072119.25841-1-dceara@redhat.com
State Accepted
Headers show
Series [ovs-dev] ovsdb-server: Fix memleak when failing to rea storage. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot success github build: passed

Commit Message

Dumitru Ceara July 14, 2021, 7:21 a.m. UTC
Fixes: 1b1d2e6daa56 ("ovsdb: Introduce experimental support for clustered databases.")
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
---
 ovsdb/ovsdb-server.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Ben Pfaff July 15, 2021, 6:54 p.m. UTC | #1
On Wed, Jul 14, 2021 at 09:21:19AM +0200, Dumitru Ceara wrote:
> Fixes: 1b1d2e6daa56 ("ovsdb: Introduce experimental support for clustered databases.")
> Signed-off-by: Dumitru Ceara <dceara@redhat.com>

Thanks!  I pushed this.  I noticed that the declaration could be moved
down to the first assignment, so I actually pushed the following.

I backported to all affected branches.

-8<--------------------------cut here-------------------------->8--

From: Dumitru Ceara <dceara@redhat.com>
Date: Wed, 14 Jul 2021 09:21:19 +0200
Subject: [PATCH] ovsdb-server: Fix memleak when failing to read storage.

Fixes: 1b1d2e6daa56 ("ovsdb: Introduce experimental support for clustered databases.")
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
---
 ovsdb/ovsdb-server.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index b09232c654ab..f4a0fac99259 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -660,8 +660,6 @@ add_db(struct server_config *config, struct db *db)
 static struct ovsdb_error * OVS_WARN_UNUSED_RESULT
 open_db(struct server_config *config, const char *filename)
 {
-    struct db *db;
-
     /* If we know that the file is already open, return a good error message.
      * Otherwise, if the file is open, we'll fail later on with a harder to
      * interpret file locking error. */
@@ -676,9 +674,6 @@ open_db(struct server_config *config, const char *filename)
         return error;
     }
 
-    db = xzalloc(sizeof *db);
-    db->filename = xstrdup(filename);
-
     struct ovsdb_schema *schema;
     if (ovsdb_storage_is_clustered(storage)) {
         schema = NULL;
@@ -691,6 +686,9 @@ open_db(struct server_config *config, const char *filename)
         }
         ovs_assert(schema && !txn_json);
     }
+
+    struct db *db = xzalloc(sizeof *db);
+    db->filename = xstrdup(filename);
     db->db = ovsdb_create(schema, storage);
     ovsdb_jsonrpc_server_add_db(config->jsonrpc, db->db);
Dumitru Ceara July 16, 2021, 7:44 a.m. UTC | #2
On 7/15/21 8:54 PM, Ben Pfaff wrote:
> On Wed, Jul 14, 2021 at 09:21:19AM +0200, Dumitru Ceara wrote:
>> Fixes: 1b1d2e6daa56 ("ovsdb: Introduce experimental support for clustered databases.")
>> Signed-off-by: Dumitru Ceara <dceara@redhat.com>
> 
> Thanks!  I pushed this.  I noticed that the declaration could be moved
> down to the first assignment, so I actually pushed the following.
> 
> I backported to all affected branches.

Thank you!
diff mbox series

Patch

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index b09232c654..2df5bc4e74 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -676,9 +676,6 @@  open_db(struct server_config *config, const char *filename)
         return error;
     }
 
-    db = xzalloc(sizeof *db);
-    db->filename = xstrdup(filename);
-
     struct ovsdb_schema *schema;
     if (ovsdb_storage_is_clustered(storage)) {
         schema = NULL;
@@ -691,6 +688,9 @@  open_db(struct server_config *config, const char *filename)
         }
         ovs_assert(schema && !txn_json);
     }
+
+    db = xzalloc(sizeof *db);
+    db->filename = xstrdup(filename);
     db->db = ovsdb_create(schema, storage);
     ovsdb_jsonrpc_server_add_db(config->jsonrpc, db->db);