qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-dispatch git commit: DISPATCH-739: Fix leaks in test code
Date Tue, 04 Apr 2017 21:26:12 GMT
Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 8e1d5cf98 -> 097000477


DISPATCH-739: Fix leaks in test code

Noisy test bugs, not problems in production code.

Note: passing code paths have been fixed, some of the tests have multiple exit
points that will leak if they fail.


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/09700047
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/09700047
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/09700047

Branch: refs/heads/master
Commit: 097000477ebc1b453c99e9fd15bd8862cf898b90
Parents: 8e1d5cf
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Apr 4 15:39:52 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Apr 4 17:21:50 2017 -0400

----------------------------------------------------------------------
 tests/buffer_test.c |  2 ++
 tests/field_test.c  | 21 +++++++++++++++++++--
 tests/parse_test.c  | 10 +++++++++-
 3 files changed, 30 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/09700047/tests/buffer_test.c
----------------------------------------------------------------------
diff --git a/tests/buffer_test.c b/tests/buffer_test.c
index 0dedad5..6dd61f6 100644
--- a/tests/buffer_test.c
+++ b/tests/buffer_test.c
@@ -81,6 +81,8 @@ static char *test_buffer_list_clone(void *context)
     // ensure copy is un-molested:
     if (!compare_buffer(&copy, (unsigned char *)pattern, pattern_len)) return "Buffer
list corrupted";
 
+    qd_buffer_list_free_buffers(&list);
+    qd_buffer_list_free_buffers(&copy);
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/09700047/tests/field_test.c
----------------------------------------------------------------------
diff --git a/tests/field_test.c b/tests/field_test.c
index fab8951..4be6e1a 100644
--- a/tests/field_test.c
+++ b/tests/field_test.c
@@ -248,6 +248,7 @@ static char* view_address_hash(void *context, qd_iterator_t *iter,
         char *got = (char*) qd_iterator_copy(iter);
         snprintf(fail_text, FAIL_TEXT_SIZE, "Addr '%s' failed.  Expected '%s', got '%s'",
                  addr, view, got);
+        free(got);
         return fail_text;
     }
     return 0;
@@ -297,7 +298,9 @@ static char* test_view_address_hash(void *context)
         qd_iterator_t *iter = qd_iterator_string(cases[idx].addr, ITER_VIEW_ADDRESS_HASH);
         char *ret = view_address_hash(context, iter, cases[idx].addr, cases[idx].view);
         qd_iterator_free(iter);
-        if (ret) return ret;
+        if (ret) {
+            return strncpy(fail_text, ret, FAIL_TEXT_SIZE);
+        }
     }
 
     for (idx = 0; cases[idx].addr; idx++) {
@@ -375,6 +378,7 @@ static char* test_view_address_with_space(void *context)
         qd_iterator_annotate_space(iter, "space/", 6);
         char *ret = view_address_hash(context, iter, cases[idx].addr, cases[idx].view);
         release_buffer_chain(&chain);
+        qd_iterator_free(iter);
         if (ret) return ret;
     }
 
@@ -400,6 +404,7 @@ static char* test_view_address_hash_override(void *context)
             char *got = (char*) qd_iterator_copy(iter);
             snprintf(fail_text, FAIL_TEXT_SIZE, "Addr '%s' failed.  Expected '%s', got '%s'",
                      cases[idx].addr, cases[idx].view, got);
+            qd_iterator_free(iter);
             return fail_text;
         }
         qd_iterator_free(iter);
@@ -550,6 +555,7 @@ static char *test_qd_hash_retrieve_prefix_separator(void *context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -583,6 +589,7 @@ static char *test_qd_hash_retrieve_prefix(void *context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -617,6 +624,7 @@ static char *test_qd_hash_retrieve_prefix_no_match(void *context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return "test_qd_hash_retrieve_prefix_no_match() failed";
@@ -651,6 +659,7 @@ static char *test_qd_hash_retrieve_prefix_no_match_separator(void *context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return "test_qd_hash_retrieve_prefix_no_match_separator() failed";
@@ -682,6 +691,7 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match(void *context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -713,6 +723,7 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_1(void
*context)
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -747,6 +758,7 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_slashes(void
*co
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -779,6 +791,7 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end(void
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -811,6 +824,7 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1(voi
 
     qd_iterator_free(iter);
     qd_iterator_free(address_iter);
+    qd_hash_free(hash);
 
     if(addr)
         return 0;
@@ -883,9 +897,11 @@ static char *test_prefix_hash(void *context)
             qd_iterator_free(iter);
             return error;
         }
+        qd_iterator_free(iter);
         idx++;
     }
 
+    qd_hash_free(hash);
     return 0;
 }
 
@@ -955,9 +971,11 @@ static char *test_prefix_hash_with_space(void *context)
             qd_iterator_free(iter);
             return error;
         }
+        qd_iterator_free(iter);
         idx++;
     }
 
+    qd_hash_free(hash);
     return 0;
 }
 
@@ -996,4 +1014,3 @@ int field_tests(void)
 
     return result;
 }
-

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/09700047/tests/parse_test.c
----------------------------------------------------------------------
diff --git a/tests/parse_test.c b/tests/parse_test.c
index 897cece..2e04cae 100644
--- a/tests/parse_test.c
+++ b/tests/parse_test.c
@@ -130,6 +130,7 @@ static char *test_map(void *context)
 
     qd_iterator_t     *data_iter = qd_iterator_binary(data, data_len, ITER_VIEW_ALL);
     qd_parsed_field_t *field     = qd_parse(data_iter);
+
     if (!qd_parse_ok(field)) {
         snprintf(error, 1000, "Parse failed: %s", qd_parse_error(field));
         qd_iterator_free(data_iter);
@@ -207,6 +208,8 @@ static char *test_map(void *context)
         return error;
     }
 
+    qd_iterator_free(data_iter);
+    qd_parse_free(field);
     return 0;
 }
 
@@ -258,7 +261,7 @@ static char *test_parser_errors(void *context)
 
 static char *test_tracemask(void *context)
 {
-    qd_bitmask_t    *bm;
+    qd_bitmask_t    *bm = NULL;
     qd_tracemask_t  *tm = qd_tracemask();
     qd_buffer_list_t list;
     static char      error[1024];
@@ -286,6 +289,8 @@ static char *test_tracemask(void *context)
 
     DEQ_INIT(list);
     qd_compose_take_buffers(comp, &list);
+    qd_compose_free(comp);
+
     int length = 0;
     qd_buffer_t *buf = DEQ_HEAD(list);
     while (buf) {
@@ -295,6 +300,7 @@ static char *test_tracemask(void *context)
 
     qd_iterator_t     *iter = qd_iterator_buffer(DEQ_HEAD(list), 0, length, ITER_VIEW_ALL);
     qd_parsed_field_t *pf   = qd_parse(iter);
+    qd_iterator_free(iter);
 
     bm = qd_tracemask_create(tm, pf);
     if (qd_bitmask_cardinality(bm) != 3) {
@@ -316,6 +322,7 @@ static char *test_tracemask(void *context)
     qd_tracemask_remove_link(tm, 0);
 
     bm = qd_tracemask_create(tm, pf);
+    qd_parse_free(pf);
     if (qd_bitmask_cardinality(bm) != 1) {
         sprintf(error, "Expected cardinality of 1, got %d", qd_bitmask_cardinality(bm));
         return error;
@@ -331,6 +338,7 @@ static char *test_tracemask(void *context)
     }
 
     qd_tracemask_free(tm);
+    qd_bitmask_free(bm);
     return 0;
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message