[ovs-dev,09/10] db-ctl-base: Free leaked ovsdb_datum
diff mbox series

Message ID 1568236716-18105-9-git-send-email-pkusunyifeng@gmail.com
State New
Headers show
Series
  • [ovs-dev,01/10] raft: Free leaked json data
Related show

Commit Message

Yifeng Sun Sept. 11, 2019, 9:18 p.m. UTC
Valgrind reported:

2491: database commands -- negative checks

==19245== 36 (32 direct, 4 indirect) bytes in 1 blocks are definitely lost in loss record 36 of 53
==19245==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19245==    by 0x431AB4: xrealloc (util.c:149)
==19245==    by 0x41656D: ovsdb_datum_reallocate (ovsdb-data.c:1883)
==19245==    by 0x41656D: ovsdb_datum_union (ovsdb-data.c:1961)
==19245==    by 0x4107B2: cmd_add (db-ctl-base.c:1494)
==19245==    by 0x406E2E: do_vsctl (ovs-vsctl.c:2626)
==19245==    by 0x406E2E: main (ovs-vsctl.c:183)

==19252== 16 bytes in 1 blocks are definitely lost in loss record 9 of 52
==19252==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==19252==    by 0x430F74: xmalloc (util.c:138)
==19252==    by 0x414D07: clone_atoms (ovsdb-data.c:990)
==19252==    by 0x4153F6: ovsdb_datum_clone (ovsdb-data.c:1012)
==19252==    by 0x4104D3: cmd_remove (db-ctl-base.c:1564)
==19252==    by 0x406E2E: do_vsctl (ovs-vsctl.c:2626)
==19252==    by 0x406E2E: main (ovs-vsctl.c:183)

This patch fixes them.

Signed-off-by: Yifeng Sun <pkusunyifeng@gmail.com>
---
 lib/db-ctl-base.c | 5 +++++
 1 file changed, 5 insertions(+)

Patch
diff mbox series

diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index 3bd9f006acb1..6878d6326cae 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -1489,6 +1489,7 @@  cmd_add(struct ctl_context *ctx)
         ctx->error = ovsdb_datum_from_string(&add, &add_type, ctx->argv[i],
                                              ctx->symtab);
         if (ctx->error) {
+            ovsdb_datum_destroy(&old, &column->type);
             return;
         }
         ovsdb_datum_union(&old, &add, type, false);
@@ -1500,6 +1501,7 @@  cmd_add(struct ctl_context *ctx)
                   old.n,
                   type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
                   column->name, table->name, type->n_max);
+        ovsdb_datum_destroy(&old, &column->type);
         return;
     }
     ovsdb_idl_txn_verify(row, column);
@@ -1581,10 +1583,12 @@  cmd_remove(struct ctl_context *ctx)
                                                      ctx->argv[i],
                                                      ctx->symtab);
                 if (ctx->error) {
+                    ovsdb_datum_destroy(&old, &column->type);
                     return;
                 }
             } else {
                 ctx->error = error;
+                ovsdb_datum_destroy(&old, &column->type);
                 return;
             }
         }
@@ -1596,6 +1600,7 @@  cmd_remove(struct ctl_context *ctx)
                   "table %s but the minimum number is %u", old.n,
                   type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
                   column->name, table->name, type->n_min);
+        ovsdb_datum_destroy(&old, &column->type);
         return;
     }
     ovsdb_idl_txn_verify(row, column);