ovsdb-server: Fix various memory leaks.
authorBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 22:40:25 +0000 (14:40 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 23:21:09 +0000 (15:21 -0800)
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
ovsdb/jsonrpc-server.c
ovsdb/ovsdb.c
ovsdb/transaction.c

index 4cb8b14..514a278 100644 (file)
@@ -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);
 
index 458c52d..6f2a656 100644 (file)
@@ -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;
 }
 
index 27254e6..e95d23c 100644 (file)
@@ -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);
index 45b2083..15b87da 100644 (file)
@@ -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);
     }