From ab9a0b9b410a6261ddc98d4bc02bb2e4cd15b780 Mon Sep 17 00:00:00 2001 From: Dumitru Ceara 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 Signed-off-by: Ben Pfaff --- 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 03405f65362..6778efa7628 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -635,8 +635,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. */ @@ -651,9 +649,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; @@ -666,6 +661,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);