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 4cb8b14c4a46193bdbe9bf6195abc8e8cfba0b33..514a278481f6ee8873ebe681e1e512176d1f490e 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 458c52db5a0c07c1a593e728d9857e262fd85d5c..6f2a656e59c920f9f1041f2d08b2289b7579f129 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 27254e633e2e38867212e2d26f45b25cbf13a342..e95d23c415f608b88677064756c1c75096ec76e5 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 45b208394267875d050b1abbcf3ecc8422b62c5a..15b87daa41799467ecf23a54c52c4e701328abaf 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);
     }