diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2020-05-14 22:10:45 +0200 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2020-05-28 11:49:13 +0200 |
commit | fed327abf53abbf82541bd152b6650aed939f5e9 (patch) | |
tree | 0a0b3bca77d07abe7b2835f2b41898aacfcc0965 | |
parent | 5f756b8c4828fae4843a9e2e2a374feca4ffea81 (diff) | |
download | openvswitch-fed327abf53abbf82541bd152b6650aed939f5e9.tar.gz |
ovsdb-server: Fix schema leak while reading db.
parse_txn() function doesn't always take ownership of the 'schema'
passed. So, if the schema of the clustered db has same version as the
one that already in use, parse_txn() will not use it, resulting with a
memory leak:
7,827 (56 direct, 7,771 indirect) bytes in 1 blocks are definitely lost
at 0x483BB1A: calloc (vg_replace_malloc.c:762)
by 0x44AD02: xcalloc (util.c:121)
by 0x40E70E: ovsdb_schema_create (ovsdb.c:41)
by 0x40EA6D: ovsdb_schema_from_json (ovsdb.c:217)
by 0x415EDD: ovsdb_storage_read (storage.c:280)
by 0x408968: read_db (ovsdb-server.c:607)
by 0x40733D: main_loop (ovsdb-server.c:227)
by 0x40733D: main (ovsdb-server.c:469)
While we could put ovsdb_schema_destroy() in a few places inside
'parse_txn()', from the users' point of view it seems better to have a
constant argument and just clone the 'schema' if needed. The caller
will be responsible for destroying the 'schema' it owns.
Fixes: 1b1d2e6daa56 ("ovsdb: Introduce experimental support for clustered databases.")
Acked-by: Han Zhou <hzhou@ovn.org>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r-- | ovsdb/ovsdb-server.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index d803a3d1b..312108f41 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -531,7 +531,7 @@ close_db(struct server_config *config, struct db *db, char *comment) static struct ovsdb_error * OVS_WARN_UNUSED_RESULT parse_txn(struct server_config *config, struct db *db, - struct ovsdb_schema *schema, const struct json *txn_json, + const struct ovsdb_schema *schema, const struct json *txn_json, const struct uuid *txnid) { if (schema && (!db->db->schema || strcmp(schema->version, @@ -556,7 +556,7 @@ parse_txn(struct server_config *config, struct db *db, ? xasprintf("database %s schema changed", db->db->name) : xasprintf("database %s connected to storage", db->db->name))); - ovsdb_replace(db->db, ovsdb_create(schema, NULL)); + ovsdb_replace(db->db, ovsdb_create(ovsdb_schema_clone(schema), NULL)); /* Force update to schema in _Server database. */ db->row_uuid = UUID_ZERO; @@ -605,6 +605,7 @@ read_db(struct server_config *config, struct db *db) } else { error = parse_txn(config, db, schema, txn_json, &txnid); json_destroy(txn_json); + ovsdb_schema_destroy(schema); if (error) { break; } |