[ovs-dev] Subject: [ovsdb-idl 1/1] Fix issues detected in Partial Map Update feature

Lutz, Arnoldo arnoldo.lutz.guevara at hpe.com
Mon Jun 13 16:06:48 UTC 2016


Hi. 
We found some issues affecting Partial Map Update feature included in master branch.
This patch fixes a memory leak due to lack of freeing datum allocated in the process of
requesting a change to a map.
It also fix an error produced when NDEBUG flag is not set that causes an assertion when preparing
the map to be changed.


>From 540230095eb5d552bb1cc559abb1bbdc668197b1 Mon Sep 17 00:00:00 2001
From: "arnoldo.lutz.guevara at hpe.com" <arnoldo.lutz.guevara at hpe.com>
Date: Thu, 9 Jun 2016 09:41:00 -0700
Subject: [ovsdb-idl 1/1] Fix issues detected in Partial Map Update feature

Fix of a memory leak not freeing datums.
Change use of ovsdb_idl_read function when preparing changes to maps.

Signed-off-by: arnoldo.lutz.guevara at hpe.com <arnoldo.lutz.guevara at hpe.com>
---
 lib/ovsdb-idl.c    | 13 ++++++++++++-
 lib/ovsdb-map-op.c |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index 2b372cb..b2b84c2 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -2225,7 +2225,16 @@ ovsdb_idl_txn_extract_mutations(struct ovsdb_idl_row *row,
         column = &class->columns[idx];
         key_type = column->type.key.type;
         value_type = column->type.value.type;
-        old_datum = ovsdb_idl_read(row, column);
+
+        /* Get the value to be changed */
+        if (row->new && row->written && bitmap_is_set(row->written,idx)) {
+            old_datum = &row->new[idx];
+        } else if (row->old != NULL) {
+            old_datum = &row->old[idx];
+        } else {
+            old_datum = CONST_CAST(struct ovsdb_datum*,
+                                ovsdb_datum_default(&column->type));
+        }
 
         del_set = json_array_create_empty();
         ins_map = json_array_create_empty();
@@ -3407,6 +3416,7 @@ ovsdb_idl_txn_write_partial_map(const struct ovsdb_idl_row *row_,
 
     if (!is_valid_partial_update(row, column, datum)) {
         ovsdb_datum_destroy(datum, &column->type);
+        free(datum);
         return;
     }
 
@@ -3437,6 +3447,7 @@ ovsdb_idl_txn_delete_partial_map(const struct ovsdb_idl_row *row_,
         struct ovsdb_type type_ = column->type;
         type_.value.type = OVSDB_TYPE_VOID;
         ovsdb_datum_destroy(datum, &type_);
+        free(datum);
         return;
     }
     ovsdb_idl_txn_add_map_op(row, column, datum, MAP_OP_DELETE);
diff --git a/lib/ovsdb-map-op.c b/lib/ovsdb-map-op.c
index 58f43dc..23fc5f5 100644
--- a/lib/ovsdb-map-op.c
+++ b/lib/ovsdb-map-op.c
@@ -57,6 +57,7 @@ map_op_destroy_datum(struct map_op *map_op, const struct ovsdb_type *type)
     } else {
         ovsdb_datum_destroy(map_op->datum, type);
     }
+    free(map_op->datum);
     map_op->datum = NULL;
 }
 
-- 
1.9.1



More information about the dev mailing list