From e084f69017bc840cd7aed4cc9ed2e13f3fb6747e Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 2 Feb 2010 14:40:25 -0800 Subject: [PATCH] ovsdb-server: Fix various memory leaks. Some of these are serious leaks, in that they could leak some amount of memory for every transaction processed by the database server. Found with valgrind. --- ovsdb/execution.c | 9 ++++++--- ovsdb/jsonrpc-server.c | 3 +++ ovsdb/ovsdb.c | 4 ++-- ovsdb/transaction.c | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ovsdb/execution.c b/ovsdb/execution.c index 4cb8b14c4..514a27848 100644 --- a/ovsdb/execution.c +++ b/ovsdb/execution.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -161,9 +161,11 @@ ovsdb_execute(struct ovsdb *db, const struct json *params, && timeout_msec) { ovsdb_txn_abort(x.txn); *timeout_msec = x.timeout_msec; - ovsdb_error_destroy(error); + + json_destroy(result); json_destroy(results); - return NULL; + results = NULL; + goto exit; } /* Add result to array. */ @@ -186,6 +188,7 @@ ovsdb_execute(struct ovsdb *db, const struct json *params, json_array_add(results, json_null_create()); } +exit: ovsdb_error_destroy(error); ovsdb_symbol_table_destroy(x.symtab); diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 458c52db5..6f2a656e5 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -252,9 +252,11 @@ ovsdb_jsonrpc_session_create(struct ovsdb_jsonrpc_remote *remote, static void ovsdb_jsonrpc_session_close(struct ovsdb_jsonrpc_session *s) { + ovsdb_jsonrpc_monitor_remove_all(s); jsonrpc_session_close(s->js); list_remove(&s->node); s->remote->server->n_sessions--; + free(s); } static int @@ -339,6 +341,7 @@ execute_transaction(struct ovsdb_jsonrpc_session *s, ovsdb_jsonrpc_trigger_create(s, request->id, request->params); request->id = NULL; request->params = NULL; + jsonrpc_msg_destroy(request); return NULL; } diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index 27254e633..e95d23c41 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009 Nicira Networks +/* Copyright (c) 2009, 2010 Nicira Networks * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,8 +68,8 @@ ovsdb_schema_from_file(const char *file_name, struct ovsdb_schema **schemap) } error = ovsdb_schema_from_json(json, &schema); + json_destroy(json); if (error) { - json_destroy(json); return ovsdb_wrap_error(error, "failed to parse \"%s\" as ovsdb schema", file_name); diff --git a/ovsdb/transaction.c b/ovsdb/transaction.c index 45b208394..15b87daa4 100644 --- a/ovsdb/transaction.c +++ b/ovsdb/transaction.c @@ -284,6 +284,7 @@ ovsdb_txn_row_delete(struct ovsdb_txn *txn, const struct ovsdb_row *row_) } else { txn_table = ovsdb_txn_get_txn_table(txn, table); hmap_remove(&txn_table->txn_rows, &txn_row->hmap_node); + free(txn_row); } ovsdb_row_destroy(row); } -- 2.43.0