This patch addresses several common issues in various test programs
instead of sending multiple small patches.  While these are not
critical, cleaning them up improves code quality.

- Fixed two resource leaks in test-aa.c and test-ovsdb.c.
- Fixed four instances of unchecked return values in test-ovsdb.c
  and test-packet.c.
- Fixed one out-of-bounds read in test-ccmap.c

Signed-off-by: Eelco Chaudron <[email protected]>
---
Note that 'ERROR: Use ovs_assert() in place of assert()' is
reported. However we kept assert() as it's the standard for
this file.
---
 tests/test-aa.c      |  1 +
 tests/test-ccmap.c   |  2 +-
 tests/test-ovsdb.c   | 10 +++++++---
 tests/test-packets.c |  2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/tests/test-aa.c b/tests/test-aa.c
index 0107d2263..1c0fb2926 100644
--- a/tests/test-aa.c
+++ b/tests/test-aa.c
@@ -239,6 +239,7 @@ test_aa_send(void)
 
     if (n == 0) {
         printf("Error: unable to build packet\n");
+        lldp_destroy_dummy(lldp);
         return 1;
     }
 
diff --git a/tests/test-ccmap.c b/tests/test-ccmap.c
index 5c51bbe83..dcc4a6fd6 100644
--- a/tests/test-ccmap.c
+++ b/tests/test-ccmap.c
@@ -129,7 +129,7 @@ test_ccmap_inc_dec(hash_func *hash)
         check_ccmap(&ccmap, values, i + 1, hash);
     }
     shuffle(values, N_ELEMS);
-    for (i = 0; i < N_ELEMS; i++) {
+    for (i = 0; i < (N_ELEMS - 1); i++) {
         ccmap_dec(&ccmap, hash(values[i]));
         check_ccmap(&ccmap, values + (i + 1), N_ELEMS - (i + 1), hash);
     }
diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c
index 710341b65..eb5688e46 100644
--- a/tests/test-ovsdb.c
+++ b/tests/test-ovsdb.c
@@ -426,6 +426,7 @@ do_log_io(struct ovs_cmdl_context *ctx)
     }
 
     ovsdb_log_close(log);
+    ovsdb_log_close(replacement);
 }
 
 static void
@@ -3089,7 +3090,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context 
*ctx)
     myTxn = ovsdb_idl_txn_create(idl);
     idltest_simple3_get_uset(myRow, OVSDB_TYPE_UUID);
     struct uuid uuid_to_add;
-    uuid_from_string(&uuid_to_add, "001e43d2-dd3f-4616-ab6a-83a490bb0991");
+    ovs_assert(uuid_from_string(&uuid_to_add,
+               "001e43d2-dd3f-4616-ab6a-83a490bb0991"));
     idltest_simple3_update_uset_addvalue(myRow, uuid_to_add);
     idltest_simple3_set_name(myRow, "String2");
     ovsdb_idl_txn_commit_block(myTxn);
@@ -3101,7 +3103,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context 
*ctx)
     /* Insert duplicate element. */
     myTxn = ovsdb_idl_txn_create(idl);
     struct uuid uuid_to_add2;
-    uuid_from_string(&uuid_to_add2, "0026b3ba-571b-4729-8227-d860a5210ab8");
+    ovs_assert(uuid_from_string(&uuid_to_add2,
+               "0026b3ba-571b-4729-8227-d860a5210ab8"));
     idltest_simple3_update_uset_addvalue(myRow, uuid_to_add2);
     ovsdb_idl_txn_commit_block(myTxn);
     ovsdb_idl_txn_destroy(myTxn);
@@ -3145,7 +3148,8 @@ do_idl_partial_update_set_column(struct ovs_cmdl_context 
*ctx)
     /* create row, insert key, delete row */
     myTxn = ovsdb_idl_txn_create(idl);
     myRow = idltest_simple3_insert(myTxn);
-    uuid_from_string(&uuid_to_add, "12345678-dd3f-4616-ab6a-83a490bb0991");
+    ovs_assert(uuid_from_string(&uuid_to_add,
+               "12345678-dd3f-4616-ab6a-83a490bb0991"));
     idltest_simple3_update_uset_addvalue(myRow, uuid_to_add);
     idltest_simple3_set_name(myRow, "String2");
     idltest_simple3_delete(myRow);
diff --git a/tests/test-packets.c b/tests/test-packets.c
index da074f74d..6151c633c 100644
--- a/tests/test-packets.c
+++ b/tests/test-packets.c
@@ -157,7 +157,7 @@ test_ipv6_parsing(void)
     struct in6_addr o_ipv6, p_ipv6;
     struct in6_addr mask;
 
-    inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", &o_ipv6);
+    assert(inet_pton(AF_INET6, "2001:db8:0:0:0:0:2:1", &o_ipv6) == 1);
 
     assert(!ipv6_parse_masked("2001:db8:0:0:0:0:2:1/64", &p_ipv6, &mask));
     assert(ipv6_addr_equals(&o_ipv6, &p_ipv6));
-- 
2.47.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to