qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject qpid-dispatch git commit: DISPATCH-1222: clean up various issues reported by coverity
Date Thu, 13 Dec 2018 19:44:25 GMT
Repository: qpid-dispatch
Updated Branches:
  refs/heads/master a3be94a6d -> 16674f44b


DISPATCH-1222: clean up various issues reported by coverity


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

Branch: refs/heads/master
Commit: 16674f44b0cdf037614e8e4378e24e9af0eb7ab9
Parents: a3be94a
Author: Kenneth Giusti <kgiusti@apache.org>
Authored: Thu Dec 13 14:28:37 2018 -0500
Committer: Kenneth Giusti <kgiusti@apache.org>
Committed: Thu Dec 13 14:35:23 2018 -0500

----------------------------------------------------------------------
 src/address_lookup_utils.c                      |  17 +-
 src/message.c                                   |   1 -
 src/router_core/core_client_api.c               |   8 +-
 .../address_lookup_client/lookup_client.c       |   2 -
 .../address_lookup_server.c                     |   5 +-
 src/router_core/modules/edge_router/edge_mgmt.c |  12 +-
 .../modules/test_hooks/core_test_hooks.c        |   6 +-
 tests/field_test.c                              |  96 +++++--
 tests/message_test.c                            |  69 +++++-
 tests/parse_test.c                              |  61 +++--
 tests/parse_tree_tests.c                        | 248 ++++++++++++++-----
 tests/policy_test.c                             |  66 +++--
 tests/tool_test.c                               |  80 ++++--
 13 files changed, 507 insertions(+), 164 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/address_lookup_utils.c
----------------------------------------------------------------------
diff --git a/src/address_lookup_utils.c b/src/address_lookup_utils.c
index 9935cf5..c7846d7 100644
--- a/src/address_lookup_utils.c
+++ b/src/address_lookup_utils.c
@@ -66,18 +66,23 @@ qcm_address_lookup_status_t qcm_link_route_lookup_decode(qd_iterator_t *properti
                                                          bool          *is_link_route,
                                                          bool          *has_destinations)
 {
+    qd_parsed_field_t *props = NULL;
+    qd_parsed_field_t *bod = NULL;
+
     qcm_address_lookup_status_t rc = QCM_ADDR_LOOKUP_OK;
     *is_link_route = false;
     *has_destinations = false;
 
-    qd_parsed_field_t *props = qd_parse(properties);
-    if (!props || !qd_parse_ok(props) || !qd_parse_is_map(props))
-        return QCM_ADDR_LOOKUP_INVALID_REQUEST;
+    props = qd_parse(properties);
+    if (!props || !qd_parse_ok(props) || !qd_parse_is_map(props)) {
+        rc = QCM_ADDR_LOOKUP_INVALID_REQUEST;
+        goto exit;
+    }
 
-    qd_parsed_field_t *bod = qd_parse(body);
+    bod = qd_parse(body);
     if (!bod || !qd_parse_ok(bod) || !qd_parse_is_list(bod)) {
-        qd_parse_free(props);
-        return QCM_ADDR_LOOKUP_INVALID_REQUEST;
+        rc = QCM_ADDR_LOOKUP_INVALID_REQUEST;
+        goto exit;
     }
 
     qd_parsed_field_t *tmp = qd_parse_value_by_key(props, "status");

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/message.c
----------------------------------------------------------------------
diff --git a/src/message.c b/src/message.c
index d82a670..16060d3 100644
--- a/src/message.c
+++ b/src/message.c
@@ -788,7 +788,6 @@ static void qd_message_parse_priority(qd_message_t *in_msg)
                 qd_parsed_field_t *priority_field = qd_parse_sub_value(field, 1);
                 if (qd_parse_tag(priority_field) != QD_AMQP_NULL) {
                     uint32_t value = qd_parse_as_uint(priority_field);
-                    content->priority = value >= QDR_N_PRIORITIES ? QDR_N_PRIORITIES - 1 : (uint8_t) (value & 0x00ff);
                     content->priority = value > QDR_MAX_PRIORITY ? QDR_MAX_PRIORITY : (uint8_t) (value & 0x00ff);
                     content->priority_present = true;
                 }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/router_core/core_client_api.c
----------------------------------------------------------------------
diff --git a/src/router_core/core_client_api.c b/src/router_core/core_client_api.c
index 4967aec..45c7150 100644
--- a/src/router_core/core_client_api.c
+++ b/src/router_core/core_client_api.c
@@ -237,7 +237,7 @@ int qdrc_client_request_CT(qdrc_client_t                 *client,
                            qdrc_client_request_done_CT_t  done_cb)
 {
     qd_log(client->core->log, QD_LOG_TRACE,
-           "New core client request created c=%p, rc=%"PRIuPTR,
+           "New core client request created c=%p, rc=%p",
            client, request_context);
 
     qdrc_client_request_t *req = new_qdrc_client_request_t();
@@ -294,7 +294,7 @@ static void _flush_send_queue_CT(qdrc_client_t *client)
         req->on_send_queue = false;
 
         qd_log(client->core->log, QD_LOG_TRACE,
-               "Core client request sent c=%p, rc=%"PRIuPTR" dlv=%p cid=%s",
+               "Core client request sent c=%p, rc=%p dlv=%p cid=%s",
                client, req->req_context, req->delivery,
                *req->correlation_id ? req->correlation_id : "<none>");
 
@@ -357,7 +357,7 @@ static void _free_request_CT(qdrc_client_t *client,
     }
 
     qd_log(client->core->log, QD_LOG_TRACE,
-           "Freeing core client request c=%p, rc=%"PRIuPTR" (%s)",
+           "Freeing core client request c=%p, rc=%p (%s)",
            client, req->req_context,
            error ? error : "request complete");
 
@@ -519,7 +519,7 @@ static void _receiver_transfer_CT(void *client_context,
             if (req) {
 
                 qd_log(core->log, QD_LOG_TRACE,
-                       "Core client received msg c=%p rc=%"PRIuPTR" cid=%s",
+                       "Core client received msg c=%p rc=%p cid=%s",
                        client, req->req_context, req->correlation_id);
 
                 qd_hash_remove_by_handle(client->correlations, req->hash_handle);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/router_core/modules/address_lookup_client/lookup_client.c
----------------------------------------------------------------------
diff --git a/src/router_core/modules/address_lookup_client/lookup_client.c b/src/router_core/modules/address_lookup_client/lookup_client.c
index 483c3c2..5e6d4a7 100644
--- a/src/router_core/modules/address_lookup_client/lookup_client.c
+++ b/src/router_core/modules/address_lookup_client/lookup_client.c
@@ -559,8 +559,6 @@ static void on_state(qdr_core_t    *core,
         while (request) {
             DEQ_REMOVE_HEAD(client->pending_requests);
             qcm_addr_lookup_local_search(client, request);
-            qdr_terminus_free(request->source);
-            qdr_terminus_free(request->target);
             free_qcm_addr_lookup_request_t(request);
             request = DEQ_HEAD(client->pending_requests);
         }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/router_core/modules/address_lookup_server/address_lookup_server.c
----------------------------------------------------------------------
diff --git a/src/router_core/modules/address_lookup_server/address_lookup_server.c b/src/router_core/modules/address_lookup_server/address_lookup_server.c
index b37e23d..194dba2 100644
--- a/src/router_core/modules/address_lookup_server/address_lookup_server.c
+++ b/src/router_core/modules/address_lookup_server/address_lookup_server.c
@@ -306,11 +306,12 @@ static void _on_first_detach(void *link_context,
                              qdr_error_t *error)
 {
     _endpoint_ref_t *epr = (_endpoint_ref_t *)link_context;
-    qdrc_endpoint_detach_CT(_server_state.core, epr->endpoint, 0);
-    DEQ_REMOVE(_server_state.endpoints, epr);
     qd_log(_server_state.core->log, QD_LOG_TRACE,
            "Client detached from address lookup server (container=%s, endpoint=%p)",
            epr->container_id, (void *)epr->endpoint);
+
+    qdrc_endpoint_detach_CT(_server_state.core, epr->endpoint, 0);
+    DEQ_REMOVE(_server_state.endpoints, epr);
     free__endpoint_ref_t(epr);
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/router_core/modules/edge_router/edge_mgmt.c
----------------------------------------------------------------------
diff --git a/src/router_core/modules/edge_router/edge_mgmt.c b/src/router_core/modules/edge_router/edge_mgmt.c
index 1fc929a..7dd6245 100644
--- a/src/router_core/modules/edge_router/edge_mgmt.c
+++ b/src/router_core/modules/edge_router/edge_mgmt.c
@@ -135,7 +135,7 @@ static void _mgmt_on_state_cb_CT(qdr_core_t    *core,
                                  bool           active)
 {
     qd_log(core->log, QD_LOG_TRACE,
-           "edge mgmt client state change: uc=%"PRIuPTR" %s",
+           "edge mgmt client state change: uc=%p %s",
            user_context,
            (active) ? "active" : "down");
 
@@ -154,7 +154,7 @@ static void _mgmt_on_flow_cb_CT(qdr_core_t    *core,
                                 bool           drain)
 {
     qd_log(core->log, QD_LOG_TRACE,
-           "edge mgmt client flow: uc=%"PRIuPTR" c=%d d=%s",
+           "edge mgmt client flow: uc=%p c=%d d=%s",
            user_context, available_credit,
            (drain) ? "T" : "F");
 
@@ -174,7 +174,7 @@ static void _mgmt_on_ack_cb_CT(qdr_core_t    *core,
     qcm_edge_mgmt_request_t *req = (qcm_edge_mgmt_request_t *)request_context;
 
     qd_log(core->log, QD_LOG_TRACE,
-           "edge mgmt request update: rc=%"PRIuPTR" d=0x%"PRIx64,
+           "edge mgmt request update: rc=%p d=0x%"PRIx64,
            req->req_context, disposition);
 
     if (disposition != PN_ACCEPTED) {
@@ -209,7 +209,7 @@ static uint64_t _mgmt_on_reply_cb_CT(qdr_core_t    *core,
 
     qd_log(core->log, QD_LOG_TRACE,
            "Edge management request reply:"
-           " rc=%"PRIuPTR" status=%"PRId32": %s",
+           " rc=%p status=%"PRId32": %s",
            req->req_context, statusCode,
            (statusDescription) ? statusDescription : "<no description>");
 
@@ -233,7 +233,7 @@ static void _mgmt_on_done_cb_CT(qdr_core_t    *core,
 {
     qcm_edge_mgmt_request_t *req = (qcm_edge_mgmt_request_t *)request_context;
     qd_log(core->log, QD_LOG_TRACE,
-           "edge mgmt request done: uc=%"PRIuPTR" rc=%"PRIuPTR" %s",
+           "edge mgmt request done: uc=%p rc=%p %s",
            user_context, request_context, error ? error : "");
 
     if (error && req->error_callback)
@@ -257,7 +257,7 @@ int qcm_edge_mgmt_request_CT(qdr_core_t           *core,
 {
 
     qd_log(core->log, QD_LOG_TRACE,
-           "New Edge management request: rc=%"PRIuPTR" %s type=%s id=%s",
+           "New Edge management request: rc=%p %s type=%s id=%s",
            request_context, operation, entity_type,
            (identity) ? identity : "<unset>");
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/src/router_core/modules/test_hooks/core_test_hooks.c
----------------------------------------------------------------------
diff --git a/src/router_core/modules/test_hooks/core_test_hooks.c b/src/router_core/modules/test_hooks/core_test_hooks.c
index ef09ee4..c3d25a3 100644
--- a/src/router_core/modules/test_hooks/core_test_hooks.c
+++ b/src/router_core/modules/test_hooks/core_test_hooks.c
@@ -491,7 +491,7 @@ static uint64_t _client_on_reply_cb(qdr_core_t    *core,
                                     qd_iterator_t *body)
 {
     qd_log(core->log, QD_LOG_TRACE,
-           "client test reply received rc=%"PRIxPTR, request_context);
+           "client test reply received rc=%p", request_context);
 
     qd_iterator_free(app_properties);
     qd_iterator_free(body);
@@ -507,7 +507,7 @@ static void _client_on_ack_cb(qdr_core_t    *core,
 {
     test_client_t *tc = (test_client_t *)user_context;
     qd_log(core->log, QD_LOG_TRACE,
-           "client test request ack rc=%"PRIxPTR" d=%"PRIu64,
+           "client test request ack rc=%p d=%"PRIu64,
            request_context, disposition);
     assert((int64_t)request_context < tc->counter);
 }
@@ -553,7 +553,7 @@ static void _do_send(test_client_t *tc)
         ++tc->counter;
         --tc->credit;
         qd_log(tc->module->core->log, QD_LOG_TRACE,
-               "client test message sent id=%d c=%d", tc->counter + 1, tc->credit);
+               "client test message sent id=%"PRIi64" c=%d", tc->counter + 1, tc->credit);
     }
 }
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/field_test.c
----------------------------------------------------------------------
diff --git a/tests/field_test.c b/tests/field_test.c
index 74fb681..98b50d4 100644
--- a/tests/field_test.c
+++ b/tests/field_test.c
@@ -56,16 +56,22 @@ static void release_buffer_chain(qd_buffer_list_t *chain)
 static char* test_view_global_dns(void *context)
 {
     qd_iterator_t *iter = qd_iterator_string("amqp://host/global/sub", ITER_VIEW_ALL);
-    if (!qd_iterator_equal(iter, (unsigned char*) "amqp://host/global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "amqp://host/global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ALL failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_NO_HOST);
-    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_NO_HOST failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_HASH);
-    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_HASH failed";
+    }
 
     qd_iterator_free(iter);
 
@@ -76,16 +82,22 @@ static char* test_view_global_dns(void *context)
 static char* test_view_global_non_dns(void *context)
 {
     qd_iterator_t *iter = qd_iterator_string("amqp:/global/sub", ITER_VIEW_ALL);
-    if (!qd_iterator_equal(iter, (unsigned char*) "amqp:/global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "amqp:/global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ALL failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_NO_HOST);
-    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_NO_HOST failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_HASH);
-    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_HASH failed";
+    }
 
     qd_iterator_free(iter);
 
@@ -96,16 +108,22 @@ static char* test_view_global_non_dns(void *context)
 static char* test_view_global_no_host(void *context)
 {
     qd_iterator_t *iter = qd_iterator_string("global/sub", ITER_VIEW_ALL);
-    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ALL failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_NO_HOST);
-    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_NO_HOST failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_HASH);
-    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_HASH failed";
+    }
 
     qd_iterator_free(iter);
 
@@ -116,16 +134,22 @@ static char* test_view_global_no_host(void *context)
 static char* test_view_global_no_host_slash(void *context)
 {
     qd_iterator_t *iter = qd_iterator_string("/global/sub", ITER_VIEW_ALL);
-    if (!qd_iterator_equal(iter, (unsigned char*) "/global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "/global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ALL failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_NO_HOST);
-    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_NO_HOST failed";
+    }
 
     qd_iterator_reset_view(iter, ITER_VIEW_ADDRESS_HASH);
-    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub"))
+    if (!qd_iterator_equal(iter, (unsigned char*) "M0global/sub")) {
+        qd_iterator_free(iter);
         return "ITER_VIEW_ADDRESS_HASH failed";
+    }
 
     qd_iterator_free(iter);
 
@@ -545,6 +569,7 @@ static char *field_advance_test(void *context,
             snprintf(fail_text, FAIL_TEXT_SIZE,
                      "Field advance failed.  Expected '%s'",
                      (char *)template );
+            qd_iterator_free(raw);
             return fail_text;
         }
         qd_iterator_advance(iter, increment);
@@ -601,8 +626,11 @@ static char *test_qd_hash_retrieve_prefix_separator(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.org.apache.dev";
 
@@ -635,8 +663,11 @@ static char *test_qd_hash_retrieve_prefix(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.org.apache.dev";
 
@@ -670,8 +701,11 @@ static char *test_qd_hash_retrieve_prefix_no_match(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.org.apache.dev";
 
@@ -705,8 +739,11 @@ static char *test_qd_hash_retrieve_prefix_no_match_separator(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.org.apache.dev";
 
@@ -737,8 +774,11 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy";
 
@@ -769,8 +809,11 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_1(void *context)
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.apache.org";
 
@@ -804,8 +847,11 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_slashes(void *co
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy/apache/org";
 
@@ -837,8 +883,11 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end(void
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.";
 
@@ -870,8 +919,11 @@ static char *test_qd_hash_retrieve_prefix_separator_exact_match_dot_at_end_1(voi
     qd_error_t error = qd_hash_insert(hash, iter, "TEST", 0);
 
     // There should be no error on the insert hash
-    if (error != QD_ERROR_NONE)
+    if (error != QD_ERROR_NONE) {
+        qd_iterator_free(iter);
+        qd_hash_free(hash);
         return "qd_hash_insert failed";
+    }
 
     const char *taddr = "policy.apache.";
 
@@ -955,6 +1007,7 @@ static char *test_prefix_hash(void *context)
             snprintf(error, 200, "Pattern: '%s', expected %d, got %d",
                      patterns[idx].pattern, patterns[idx].entry, position);
             qd_iterator_free(iter);
+            qd_hash_free(hash);
             return error;
         }
         qd_iterator_free(iter);
@@ -1029,6 +1082,7 @@ static char *test_prefix_hash_with_space(void *context)
             snprintf(error, 200, "Pattern: '%s', expected %d, got %d",
                      patterns[idx].pattern, patterns[idx].entry, position);
             qd_iterator_free(iter);
+            qd_hash_free(hash);
             return error;
         }
         qd_iterator_free(iter);

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/message_test.c
----------------------------------------------------------------------
diff --git a/tests/message_test.c b/tests/message_test.c
index 90766f7..141e6c1 100644
--- a/tests/message_test.c
+++ b/tests/message_test.c
@@ -102,7 +102,10 @@ static char* test_receive_from_messenger(void *context)
 
     size_t       size = 10000;
     int result = pn_message_encode(pn_msg, buffer, &size);
-    if (result != 0) return "Error in pn_message_encode";
+    if (result != 0) {
+        pn_message_free(pn_msg);
+        return "Error in pn_message_encode";
+    }
 
     qd_message_t         *msg     = qd_message();
     qd_message_content_t *content = MSG_CONTENT(msg);
@@ -110,26 +113,42 @@ static char* test_receive_from_messenger(void *context)
     set_content(content, size);
 
     int valid = qd_message_check(msg, QD_DEPTH_ALL);
-    if (!valid) return "qd_message_check returns 'invalid'";
+    if (!valid) {
+        pn_message_free(pn_msg);
+        qd_message_free(msg);
+        return "qd_message_check returns 'invalid'";
+    }
 
     qd_iterator_t *iter = qd_message_field_iterator(msg, QD_FIELD_TO);
-    if (iter == 0) return "Expected an iterator for the 'to' field";
+    if (iter == 0) {
+        pn_message_free(pn_msg);
+        qd_message_free(msg);
+        return "Expected an iterator for the 'to' field";
+    }
 
     if (!qd_iterator_equal(iter, (unsigned char*) "test_addr_1")) {
         qd_iterator_free(iter);
+        pn_message_free(pn_msg);
+        qd_message_free(msg);
         return "Mismatched 'to' field contents";
     }
     qd_iterator_free(iter);
 
     ssize_t  test_len = (size_t)qd_message_field_length(msg, QD_FIELD_TO);
-    if (test_len != 11)
+    if (test_len != 11) {
+        pn_message_free(pn_msg);
+        qd_message_free(msg);
         return "Incorrect field length";
+    }
 
     char test_field[100];
     size_t hdr_length;
     test_len = qd_message_field_copy(msg, QD_FIELD_TO, test_field, &hdr_length);
-    if (test_len - hdr_length != 11)
+    if (test_len - hdr_length != 11) {
+        pn_message_free(pn_msg);
+        qd_message_free(msg);
         return "Incorrect length returned from field_copy";
+    }
 
     if (test_len < 0) {
         pn_message_free(pn_msg);
@@ -178,35 +197,47 @@ static char* test_message_properties(void *context)
 
     qd_iterator_t *iter = qd_message_field_iterator(msg, QD_FIELD_CORRELATION_ID);
     if (!iter) {
+        qd_message_free(msg);
         return "Expected iterator for the 'correlation-id' field";
     }
     if (qd_iterator_length(iter) != 13) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Bad length for correlation-id";
     }
     if (!qd_iterator_equal(iter, (const unsigned char *)"correlationId")) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Invalid correlation-id";
     }
     qd_iterator_free(iter);
 
     iter = qd_message_field_iterator(msg, QD_FIELD_SUBJECT);
-    if (!iter) return "Expected iterator for the 'subject' field";
+    if (!iter) {
+        qd_iterator_free(iter);
+        qd_message_free(msg);
+        return "Expected iterator for the 'subject' field";
+    }
     if (!qd_iterator_equal(iter, (const unsigned char *)subject)) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Bad value for subject";
     }
     qd_iterator_free(iter);
 
     iter = qd_message_field_iterator(msg, QD_FIELD_MESSAGE_ID);
-    if (!iter)
+    if (!iter) {
+        qd_message_free(msg);
         return "Expected iterator for the 'message-id' field";
+    }
     if (qd_iterator_length(iter) != 9) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Bad length for message-id";
     }
     if (!qd_iterator_equal(iter, (const unsigned char *)"messageId")) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Invalid message-id";
     }
     qd_iterator_free(iter);
@@ -214,6 +245,7 @@ static char* test_message_properties(void *context)
     iter = qd_message_field_iterator(msg, QD_FIELD_TO);
     if (iter) {
         qd_iterator_free(iter);
+        qd_message_free(msg);
         return "Expected no iterator for the 'to' field";
     }
     qd_iterator_free(iter);
@@ -240,13 +272,22 @@ static char* test_check_multiple(void *context)
     set_content(content, size);
 
     int valid = qd_message_check(msg, QD_DEPTH_DELIVERY_ANNOTATIONS);
-    if (!valid) return "qd_message_check returns 'invalid' for DELIVERY_ANNOTATIONS";
+    if (!valid) {
+        qd_message_free(msg);
+        return "qd_message_check returns 'invalid' for DELIVERY_ANNOTATIONS";
+    }
 
     valid = qd_message_check(msg, QD_DEPTH_BODY);
-    if (!valid) return "qd_message_check returns 'invalid' for BODY";
+    if (!valid) {
+        qd_message_free(msg);
+        return "qd_message_check returns 'invalid' for BODY";
+    }
 
     valid = qd_message_check(msg, QD_DEPTH_PROPERTIES);
-    if (!valid) return "qd_message_check returns 'invalid' for PROPERTIES";
+    if (!valid) {
+        qd_message_free(msg);
+        return "qd_message_check returns 'invalid' for PROPERTIES";
+    }
 
     qd_message_free(msg);
 
@@ -340,10 +381,14 @@ static char* test_q2_input_holdoff_sensing(void *context)
         qd_message_content_t *content = MSG_CONTENT(msg);
 
         set_content_bufs(content, nbufs);
-        if (qd_message_Q2_holdoff_should_block(msg) != (nbufs >= QD_QLIMIT_Q2_UPPER))
+        if (qd_message_Q2_holdoff_should_block(msg) != (nbufs >= QD_QLIMIT_Q2_UPPER)) {
+            qd_message_free(msg);
             return "qd_message_holdoff_would_block was miscalculated";
-        if (qd_message_Q2_holdoff_should_unblock(msg) != (nbufs < QD_QLIMIT_Q2_LOWER))
+        }
+        if (qd_message_Q2_holdoff_should_unblock(msg) != (nbufs < QD_QLIMIT_Q2_LOWER)) {
+            qd_message_free(msg);
             return "qd_message_holdoff_would_unblock was miscalculated";
+        }
 
         qd_message_free(msg);
     }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/parse_test.c
----------------------------------------------------------------------
diff --git a/tests/parse_test.c b/tests/parse_test.c
index ac678f5..8d48c76 100644
--- a/tests/parse_test.c
+++ b/tests/parse_test.c
@@ -74,57 +74,69 @@ struct fs_vector_t {
 static char *test_parser_fixed_scalars(void *context)
 {
     int idx = 0;
+    qd_iterator_t *field = NULL;
+    qd_parsed_field_t *parsed = NULL;
     static char error[1024];
 
+    error[0] = 0;
+
     while (fs_vectors[idx].data) {
-        qd_iterator_t *field  = qd_iterator_binary(fs_vectors[idx].data,
-                                                   fs_vectors[idx].length, ITER_VIEW_ALL);
-        qd_parsed_field_t *parsed = qd_parse(field);
+        field = qd_iterator_binary(fs_vectors[idx].data,
+                                   fs_vectors[idx].length, ITER_VIEW_ALL);
+        parsed = qd_parse(field);
 
         qd_iterator_t *typed_iter = qd_parse_typed(parsed);
 
         int length = qd_iterator_length(typed_iter);
 
-        if (length != fs_vectors[idx].length)
-            return "Length of typed iterator does not match actual length";
+        if (length != fs_vectors[idx].length) {
+            strcpy(error, "Length of typed iterator does not match actual length");
+            break;
+        }
 
-        if (!qd_parse_ok(parsed)) return "Unexpected Parse Error";
+        if (!qd_parse_ok(parsed)) {
+            strcpy(error, "Unexpected Parse Error");
+            break;
+        }
         if (qd_parse_tag(parsed) != fs_vectors[idx].expected_tag) {
             sprintf(error, "(%d) Tag: Expected %02x, Got %02x", idx,
                     fs_vectors[idx].expected_tag, qd_parse_tag(parsed));
-            return error;
+            break;
         }
         if (fs_vectors[idx].check_uint &&
             qd_parse_as_uint(parsed) != fs_vectors[idx].expected_ulong) {
             sprintf(error, "(%d) UINT: Expected %"PRIx64", Got %"PRIx32, idx,
                     fs_vectors[idx].expected_ulong, qd_parse_as_uint(parsed));
-            return error;
+            break;
         }
         if (fs_vectors[idx].check_ulong &&
             qd_parse_as_ulong(parsed) != fs_vectors[idx].expected_ulong) {
             sprintf(error, "(%d) ULONG: Expected %"PRIx64", Got %"PRIx64, idx,
                     fs_vectors[idx].expected_ulong, qd_parse_as_ulong(parsed));
-            return error;
+            break;
         }
         if (fs_vectors[idx].check_int &&
             qd_parse_as_int(parsed) != fs_vectors[idx].expected_long) {
             sprintf(error, "(%d) INT: Expected %"PRIx64", Got %"PRIx32, idx,
                     fs_vectors[idx].expected_long, qd_parse_as_int(parsed));
-            return error;
+            break;
         }
         if (fs_vectors[idx].check_long &&
             qd_parse_as_long(parsed) != fs_vectors[idx].expected_long) {
             sprintf(error, "(%d) LONG: Expected %"PRIx64", Got %"PRIx64, idx,
                     fs_vectors[idx].expected_long, qd_parse_as_long(parsed));
-            return error;
+            break;
         }
         idx++;
-
         qd_iterator_free(field);
+        field = 0;
         qd_parse_free(parsed);
+        parsed = 0;
     }
 
-    return 0;
+    qd_iterator_free(field);
+    qd_parse_free(parsed);
+    return *error ? error : 0;
 }
 
 static char *test_integer_conversion(void *context)
@@ -370,10 +382,14 @@ static char *test_parser_errors(void *context)
                                                    err_vectors[idx].length, ITER_VIEW_ALL);
         qd_parsed_field_t *parsed = qd_parse(field);
         if (qd_parse_ok(parsed)) {
+            qd_parse_free(parsed);
+            qd_iterator_free(field);
             sprintf(error, "(%d) Unexpected Parse Success", idx);
             return error;
         }
         if (strcmp(qd_parse_error(parsed), err_vectors[idx].expected_error) != 0) {
+            qd_parse_free(parsed);
+            qd_iterator_free(field);
             sprintf(error, "(%d) Error: Expected %s, Got %s", idx,
                     err_vectors[idx].expected_error, qd_parse_error(parsed));
             return error;
@@ -394,6 +410,7 @@ static char *test_tracemask(void *context)
     qd_buffer_list_t list;
     static char      error[1024];
 
+    error[0] = 0;
     qd_iterator_set_address(false, "0", "ROUTER");
 
     qd_tracemask_add_router(tm, "amqp:/_topo/0/Router.A", 0);
@@ -435,11 +452,11 @@ static char *test_tracemask(void *context)
     bm = qd_tracemask_create(tm, pf, &ingress);
     if (qd_bitmask_cardinality(bm) != 3) {
         sprintf(error, "Expected cardinality of 3, got %d", qd_bitmask_cardinality(bm));
-        return error;
+        goto cleanup;
     }
     if (ingress != 0) {
         sprintf(error, "(A) Expected ingress index of 0, got %d", ingress);
-        return error;
+        goto cleanup;
     }
     int total = 0;
     int bit, c;
@@ -448,23 +465,25 @@ static char *test_tracemask(void *context)
     }
     if (total != 17) {
         sprintf(error, "Expected total bit value of 17, got %d", total);
-        return error;
+        goto cleanup;
     }
 
     qd_bitmask_free(bm);
+    bm = 0;
     qd_tracemask_del_router(tm, 3);
     qd_tracemask_remove_link(tm, 0);
 
     ingress = -1;
     bm = qd_tracemask_create(tm, pf, &ingress);
     qd_parse_free(pf);
+    pf = 0;
     if (qd_bitmask_cardinality(bm) != 1) {
         sprintf(error, "Expected cardinality of 1, got %d", qd_bitmask_cardinality(bm));
-        return error;
+        goto cleanup;
     }
     if (ingress != 0) {
         sprintf(error, "(B) Expected ingress index of 0, got %d", ingress);
-        return error;
+        goto cleanup;
     }
 
     total = 0;
@@ -473,16 +492,18 @@ static char *test_tracemask(void *context)
     }
     if (total != 3) {
         sprintf(error, "Expected total bit value of 3, got %d", total);
-        return error;
+        // fallthrough
     }
 
+cleanup:
+    qd_parse_free(pf);
     qd_tracemask_free(tm);
     qd_bitmask_free(bm);
     for (qd_buffer_t *buf = DEQ_HEAD(list); buf; buf = DEQ_HEAD(list)) {
         DEQ_REMOVE_HEAD(list);
         qd_buffer_free(buf);
     }
-    return 0;
+    return *error ? error : 0;
 }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/parse_tree_tests.c
----------------------------------------------------------------------
diff --git a/tests/parse_tree_tests.c b/tests/parse_tree_tests.c
index 1dba5ba..47b5fac 100644
--- a/tests/parse_tree_tests.c
+++ b/tests/parse_tree_tests.c
@@ -30,35 +30,75 @@ static char *test_add_remove(void *context)
     qd_parse_tree_t *node = qd_parse_tree_new(QD_PARSE_TREE_ADDRESS);
     void *payload;
 
-    if (qd_parse_tree_remove_pattern(node, piter))
+    if (qd_parse_tree_remove_pattern(node, piter)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Failed to remove a non-existing pattern";
+    }
 
-    if (qd_parse_tree_get_pattern(node, piter, &payload))
+    if (qd_parse_tree_get_pattern(node, piter, &payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Got a non-existing pattern";
+    }
 
-    if (qd_parse_tree_add_pattern(node, piter, "Hi Sam"))
+    if (qd_parse_tree_add_pattern(node, piter, "Hi Sam")) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Add returned existing value";
+    }
 
-    if (qd_parse_tree_add_pattern(node, piter2, "Bye Sam"))
+    if (qd_parse_tree_add_pattern(node, piter2, "Bye Sam")) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Add returned existing value";
+    }
 
-    if (!qd_parse_tree_get_pattern(node, piter, &payload))
+    if (!qd_parse_tree_get_pattern(node, piter, &payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp("Hi Sam", (char *)payload))
+    if (!payload || strcmp("Hi Sam", (char *)payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Got bad pattern";
+    }
 
-    if (!qd_parse_tree_get_pattern(node, piter2, &payload))
+    if (!qd_parse_tree_get_pattern(node, piter2, &payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp("Bye Sam", (char *)payload))
+    if (!payload || strcmp("Bye Sam", (char *)payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Got bad pattern";
+    }
 
-    if (!qd_parse_tree_remove_pattern(node, piter))
+    if (!qd_parse_tree_remove_pattern(node, piter)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Failed to remove an existing pattern";
+    }
 
-    if (!qd_parse_tree_remove_pattern(node, piter2))
+    if (!qd_parse_tree_remove_pattern(node, piter2)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
+        qd_iterator_free(piter2);
         return "Failed to remove an existing pattern";
+    }
 
     qd_parse_tree_free(node);
     qd_iterator_free(piter);
@@ -73,26 +113,40 @@ static char *test_add_and_match_str(void *context)
     qd_parse_tree_t *node = qd_parse_tree_new(QD_PARSE_TREE_ADDRESS);
     void *payload;
 
-    if (qd_parse_tree_add_pattern_str(node, str1, "Hi Sam"))
+    if (qd_parse_tree_add_pattern_str(node, str1, "Hi Sam")) {
+        qd_parse_tree_free(node);
         return "Add returned existing value (1)";
+    }
 
-    if (qd_parse_tree_add_pattern_str(node, str2, "Bye Sam"))
+    if (qd_parse_tree_add_pattern_str(node, str2, "Bye Sam")) {
+        qd_parse_tree_free(node);
         return "Add returned existing value (2)";
+    }
 
-    if (!qd_parse_tree_retrieve_match_str(node, str1, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, str1, &payload)) {
+        qd_parse_tree_free(node);
         return "Failed to get expected match (1)";
+    }
 
-    if (!qd_parse_tree_retrieve_match_str(node, str2, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, str2, &payload)) {
+        qd_parse_tree_free(node);
         return "Failed to get expected match (2)";
+    }
 
-    if (qd_parse_tree_retrieve_match_str(node, "notSoFast", &payload))
+    if (qd_parse_tree_retrieve_match_str(node, "notSoFast", &payload)) {
+        qd_parse_tree_free(node);
         return "Match pattern should not match but did match";
+    }
 
-    if (!qd_parse_tree_remove_pattern_str(node, str1))
+    if (!qd_parse_tree_remove_pattern_str(node, str1)) {
+        qd_parse_tree_free(node);
         return "Failed to remove an existing pattern str";
+    }
 
-    if (qd_parse_tree_retrieve_match_str(node, str1, &payload))
+    if (qd_parse_tree_retrieve_match_str(node, str1, &payload)) {
+        qd_parse_tree_free(node);
         return "Removed pattern should not match but did match";
+    }
 
     qd_parse_tree_free(node);
     return NULL;
@@ -108,57 +162,87 @@ static char *test_usurpation_recovery_str(void *context)
     void *deposed;
 
     // rightful owner is ensconsced
-    if (qd_parse_tree_add_pattern_str(node, A, (void *)A))
+    if (qd_parse_tree_add_pattern_str(node, A, (void *)A)) {
+        qd_parse_tree_free(node);
         return "Add returned existing value (1)";
+    }
 
     // matches on A or B both return A
-    if (!qd_parse_tree_retrieve_match_str(node, A, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, A, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(A, (char *)payload))
+    if (!payload || strcmp(A, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
-    if (!qd_parse_tree_retrieve_match_str(node, B, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, B, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(A, (char *)payload))
+    if (!payload || strcmp(A, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
     // usurper comes along
     usurped = qd_parse_tree_add_pattern_str(node, B, (void *)B);
-    if (!usurped || strcmp(A, (char *)usurped))
+    if (!usurped || strcmp(A, (char *)usurped)) {
+        qd_parse_tree_free(node);
         return "Usurper should have grabbed '#' optimized match";
+    }
 
     // matches on A or B both return B
-    if (!qd_parse_tree_retrieve_match_str(node, A, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, A, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(B, (char *)payload))
+    if (!payload || strcmp(B, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
-    if (!qd_parse_tree_retrieve_match_str(node, B, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, B, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(B, (char *)payload))
+    if (!payload || strcmp(B, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
     // Restore rightful owner
     deposed = qd_parse_tree_add_pattern_str(node, usurped, usurped);
-    if (!deposed || strcmp(B, (char *)deposed))
+    if (!deposed || strcmp(B, (char *)deposed)) {
+        qd_parse_tree_free(node);
         return "Failed to depose B";
+    }
 
     // matches on A or B both return A
-    if (!qd_parse_tree_retrieve_match_str(node, A, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, A, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(A, (char *)payload))
+    if (!payload || strcmp(A, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
-    if (!qd_parse_tree_retrieve_match_str(node, B, &payload))
+    if (!qd_parse_tree_retrieve_match_str(node, B, &payload)) {
+        qd_parse_tree_free(node);
         return "Could not get pattern";
+    }
 
-    if (!payload || strcmp(A, (char *)payload))
+    if (!payload || strcmp(A, (char *)payload)) {
+        qd_parse_tree_free(node);
         return "Got bad pattern";
+    }
 
     qd_parse_tree_free(node);
     return NULL;
@@ -209,26 +293,46 @@ static char *check_normalize(const char *input,
     qd_iterator_t *iter = qd_iterator_string(input, ITER_VIEW_ALL);
     void *payload;
 
-    if (qd_parse_tree_add_pattern(node, iter, (void *)input) != NULL)
+    if (qd_parse_tree_add_pattern(node, iter, (void *)input) != NULL) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Unexpected duplicate pattern";
-    if (!qd_parse_tree_get_pattern(node, iter, &payload))
+    }
+    if (!qd_parse_tree_get_pattern(node, iter, &payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Could not find added pattern";
-    if (!payload || strcmp((const char *)payload, input))
+    }
+    if (!payload || strcmp((const char *)payload, input)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Failed to find pattern";
+    }
 
     qd_parse_tree_walk(node, visit_all, &vh);
-    if (vh.count != 1)
+    if (vh.count != 1) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Did not find expected pattern";
-    if (strcmp(vh.payloads[0], input))
+    }
+    if (strcmp(vh.payloads[0], input)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Unexpected payload!";
+    }
     if (strcmp(vh.patterns[0], expected)) {
         fprintf(stderr, "%s %s\n", vh.patterns[0], expected);
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Incorrect normalization";
     }
 
     payload = qd_parse_tree_remove_pattern(node, iter);
-    if (!payload || strcmp((const char *)payload, input))
+    if (!payload || strcmp((const char *)payload, input)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(iter);
         return "Failed to remove pattern";
+    }
 
     qd_parse_tree_free(node);
     qd_iterator_free(iter);
@@ -274,8 +378,11 @@ static char *match_test(qd_parse_tree_type_t type,
     qd_parse_tree_t *node = qd_parse_tree_new(type);
     void *payload = (void *)"found";
 
-    if (qd_parse_tree_add_pattern(node, piter, payload))
+    if (qd_parse_tree_add_pattern(node, piter, payload)) {
+        qd_parse_tree_free(node);
+        qd_iterator_free(piter);
         return "Unexpected payload when adding pattern";
+    }
 
     for (int i = 0; tests[i].address && !rc; i++) {
         qd_iterator_t *iter = qd_iterator_string(tests[i].address, ITER_VIEW_ALL);
@@ -283,6 +390,9 @@ static char *match_test(qd_parse_tree_type_t type,
         if (match != tests[i].match) {
             printf("match address '%s' to pattern '%s': expected %d got %d\n",
                    tests[i].address, pattern, (int)tests[i].match, (int)match);
+            qd_iterator_free(iter);
+            qd_parse_tree_free(node);
+            qd_iterator_free(piter);
             return "Match test failed";
         }
         qd_iterator_free(iter);
@@ -509,6 +619,8 @@ static char *multiple_matches(qd_parse_tree_type_t type,
         qd_iterator_t *pattern = qd_iterator_string(patterns[i], ITER_VIEW_ALL);
         if (qd_parse_tree_add_pattern(node, pattern, (void *)patterns[i])) {
             printf("Failed to add pattern %s to parse tree\n", patterns[i]);
+            qd_iterator_free(pattern);
+            qd_parse_tree_free(node);
             return "failed adding pattern to tree";
         }
         qd_iterator_free(pattern);
@@ -517,16 +629,20 @@ static char *multiple_matches(qd_parse_tree_type_t type,
     {
         // read all patterns and verify all are present
         qd_parse_tree_walk(node, visit_all, &vh);
-        if (vh.count != PCOUNT)
+        if (vh.count != PCOUNT) {
+            qd_parse_tree_free(node);
             return "Not all patterns in tree";
+        }
         for (int i = 0; i < PCOUNT; i++) {
             bool found = false;
             for (int j = 0; j < PCOUNT; j++) {
                 if (strcmp(patterns[i], vh.patterns[j]) == 0)
                     found = true;
             }
-            if (!found)
+            if (!found) {
+                qd_parse_tree_free(node);
                 return "All patterns not visited";
+            }
         }
     }
 
@@ -539,12 +655,19 @@ static char *multiple_matches(qd_parse_tree_type_t type,
         //for (int i = 0; i < vh.count; i++)
         //  printf("%s, ", vh.patterns[i]);
         //printf("count = %d\n", vh.count);
-        if (vh.count != tests[k].count)
+        if (vh.count != tests[k].count) {
+            qd_iterator_free(find_me);
+            qd_parse_tree_free(node);
             return "Unexpected match count";
+        }
         for (int i = 0; i < tests[k].count; i++) {
-            if (strcmp(vh.patterns[i], tests[k].matches[i]))
+            if (strcmp(vh.patterns[i], tests[k].matches[i])) {
+                qd_iterator_free(find_me);
+                qd_parse_tree_free(node);
                 return "Unexpected pattern match";
+            }
         }
+
         qd_iterator_free(find_me);
     }
 
@@ -556,10 +679,15 @@ static char *multiple_matches(qd_parse_tree_type_t type,
         // printf("best match for %s: %s\n", tests[k].address, vh.patterns[0]);
         if (tests[k].count == 0) {
             if (vh.count != 0) {
+                qd_iterator_free(find_me);
+                qd_parse_tree_free(node);
                 return "Did not expect to find a best match!";
             }
-        } else if (vh.count == 0 || strcmp(vh.patterns[0], tests[k].matches[0]))
-                return "Unexpected best pattern match";
+        } else if (vh.count == 0 || strcmp(vh.patterns[0], tests[k].matches[0])) {
+            qd_iterator_free(find_me);
+            qd_parse_tree_free(node);
+            return "Unexpected best pattern match";
+        }
         qd_iterator_free(find_me);
     }
 
@@ -657,38 +785,46 @@ static char *test_multiple_matches(void *context)
 static char *test_validation(void *context)
 {
     qd_iterator_t *iter = qd_iterator_string("sam.*.am.#", ITER_VIEW_ALL);
+    qd_iterator_t *iter_good = qd_iterator_string("sam/+/a.#.m/#", ITER_VIEW_ALL);
+    qd_iterator_t *iter_bad = qd_iterator_string("sam/#/am/+", ITER_VIEW_ALL);
+    qd_iterator_t *iter_const = qd_iterator_string("sam/I/am", ITER_VIEW_ALL);
     qd_parse_tree_t *mqtt_tree = qd_parse_tree_new(QD_PARSE_TREE_MQTT);
     qd_parse_tree_t *addr_tree = qd_parse_tree_new(QD_PARSE_TREE_ADDRESS);
     qd_parse_tree_t *amqp_tree = qd_parse_tree_new(QD_PARSE_TREE_AMQP_0_10);
 
+    char *error = 0;
+
     if (!qd_parse_tree_validate_pattern(addr_tree, iter) ||
         !qd_parse_tree_validate_pattern(amqp_tree, iter)) {
-        return "expected to skip validation";
+        error = "expected to skip validation";
+        goto cleanup;
     }
-    qd_iterator_free(iter);
 
-    qd_iterator_t *iter_good = qd_iterator_string("sam/+/a.#.m/#", ITER_VIEW_ALL);
     if (!qd_parse_tree_validate_pattern(mqtt_tree, iter_good)) {
-        return "expected to pass mqtt validation";
+        error = "expected to pass mqtt validation";
+        goto cleanup;
     }
-    qd_iterator_free(iter_good);
 
-    qd_iterator_t *iter_bad = qd_iterator_string("sam/#/am/+", ITER_VIEW_ALL);
     if (qd_parse_tree_validate_pattern(mqtt_tree, iter_bad)) {
-        return "expected to fail mqtt validation";
+        error = "expected to fail mqtt validation";
+        goto cleanup;
     }
-    qd_iterator_free(iter_bad);
 
-    qd_iterator_t *iter_const = qd_iterator_string("sam/I/am", ITER_VIEW_ALL);
     if (!qd_parse_tree_validate_pattern(mqtt_tree, iter_const)) {
-        return "expected to pass mqtt constant string validation";
+        error = "expected to pass mqtt constant string validation";
+        // fallthrough
     }
+
+cleanup:
+    qd_iterator_free(iter);
+    qd_iterator_free(iter_good);
+    qd_iterator_free(iter_bad);
     qd_iterator_free(iter_const);
 
     qd_parse_tree_free(mqtt_tree);
     qd_parse_tree_free(addr_tree);
     qd_parse_tree_free(amqp_tree);
-    return NULL;
+    return error ? error : 0;
 }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/policy_test.c
----------------------------------------------------------------------
diff --git a/tests/policy_test.c b/tests/policy_test.c
index 3dbd478..23b26c8 100644
--- a/tests/policy_test.c
+++ b/tests/policy_test.c
@@ -97,40 +97,64 @@ static char *test_link_name_tree_lookup(void *context)
 
     qd_parse_tree_add_pattern_str(node, "${user}.xyz", payload);
 
-    if (!_qd_policy_approve_link_name_tree("chuck", "p,,.xyz", "chuck.xyz", node))
+    if (!_qd_policy_approve_link_name_tree("chuck", "p,,.xyz", "chuck.xyz", node)) {
+        qd_parse_tree_free(node);
         return "proposed link 'chuck.xyz' should tree-match allow links with ${user} but does not";
+    }
 
-    if (_qd_policy_approve_link_name_tree("chuck", "p,,.xyz", "chuck.xyz.ynot", node))
+    if (_qd_policy_approve_link_name_tree("chuck", "p,,.xyz", "chuck.xyz.ynot", node)) {
+        qd_parse_tree_free(node);
         return "proposed link 'chuck.xyz.ynot' should not tree-match allow links with ${user} but does";
+    }
 
     qd_parse_tree_add_pattern_str(node, "${user}.#", payload);
 
-    if (!_qd_policy_approve_link_name_tree("motronic", "p,,.#", "motronic", node))
+    if (!_qd_policy_approve_link_name_tree("motronic", "p,,.#", "motronic", node)) {
+        qd_parse_tree_free(node);
         return "proposed link 'motronic' should tree-match allow links with ${user} but does not";
+    }
 
-    if (!_qd_policy_approve_link_name_tree("motronic", "p,,.#", "motronic.stubs.wobbler", node))
+    if (!_qd_policy_approve_link_name_tree("motronic", "p,,.#", "motronic.stubs.wobbler", node)) {
+        qd_parse_tree_free(node);
         return "proposed link 'motronic.stubs.wobbler' should tree-match allow links with ${user} but does not";
+    }
 
     qd_parse_tree_t *node2 = qd_parse_tree_new(QD_PARSE_TREE_ADDRESS);
     qd_parse_tree_add_pattern_str(node2, "abc.${user}", payload);
 
-    if (!_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.chuck", node2))
+    if (!_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.chuck", node2)) {
+        qd_parse_tree_free(node);
+        qd_parse_tree_free(node2);
         return "proposed link 'abc.chuck' should tree-match allow links with ${user} but does not";
+    }
 
-    if (_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.ynot.chuck", node2))
+    if (_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.ynot.chuck", node2)) {
+        qd_parse_tree_free(node);
+        qd_parse_tree_free(node2);
         return "proposed link 'abc.ynot.chuck' should not tree-match allow links with ${user} but does";
+    }
 
-    if (_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.achuck", node2))
+    if (_qd_policy_approve_link_name_tree("chuck", "s,abc.,", "abc.achuck", node2)) {
+        qd_parse_tree_free(node);
+        qd_parse_tree_free(node2);
         return "proposed link 'abc.achuck' should not tree-match allow links with ${user} but does";
+    }
 
-    if (_qd_policy_approve_link_name_tree("chuckginormous", "s,abc.,", "abc.chuck", node2))
+    if (_qd_policy_approve_link_name_tree("chuckginormous", "s,abc.,", "abc.chuck", node2)) {
+        qd_parse_tree_free(node);
+        qd_parse_tree_free(node2);
         return "proposed link 'abc.chuck' should not tree-match allow links with ${user} but does";
+    }
 
     qd_parse_tree_t *node3 = qd_parse_tree_new(QD_PARSE_TREE_ADDRESS);
     qd_parse_tree_add_pattern_str(node3, "${user}", payload);
 
-    if (!_qd_policy_approve_link_name_tree("chuck", "p,,", "chuck", node3))
+    if (!_qd_policy_approve_link_name_tree("chuck", "p,,", "chuck", node3)) {
+        qd_parse_tree_free(node);
+        qd_parse_tree_free(node2);
+        qd_parse_tree_free(node3);
         return "proposed link 'chuck' should tree-match allow links with ${user} but does not";
+    }
 
     qd_parse_tree_free(node);
     qd_parse_tree_free(node2);
@@ -145,33 +169,45 @@ static char *test_link_name_csv_parser(void *context)
     char * result;
 
     result = qd_policy_compile_allowed_csv("ttt");
-    if (!!strcmp(result, "a,ttt,"))
+    if (!!strcmp(result, "a,ttt,")) {
+        free(result);
         return "simple csv with no subst failed";
+    }
     free(result);
 
     result = qd_policy_compile_allowed_csv("ttt,uuu,vvvv");
-    if (!!strcmp(result, "a,ttt,,a,uuu,,a,vvvv,"))
+    if (!!strcmp(result, "a,ttt,,a,uuu,,a,vvvv,")) {
+        free(result);
         return "moderate csv with no subst failed";
+    }
     free(result);
 
     result = qd_policy_compile_allowed_csv("*");
-    if (!!strcmp(result, "*,,"))
+    if (!!strcmp(result, "*,,")) {
+        free(result);
         return "wildcard csv failed";
+    }
     free(result);
 
     result = qd_policy_compile_allowed_csv("${user}-temp");
-    if (!!strcmp(result, "p,,-temp"))
+    if (!!strcmp(result, "p,,-temp")) {
+        free(result);
         return "csv with prefix subst failed";
+    }
     free(result);
 
     result = qd_policy_compile_allowed_csv("temp-${user}");
-    if (!!strcmp(result, "s,temp-,"))
+    if (!!strcmp(result, "s,temp-,")) {
+        free(result);
         return "csv with suffix subst failed";
+    }
     free(result);
 
     result = qd_policy_compile_allowed_csv("temp-${user}-home");
-    if (!!strcmp(result, "e,temp-,-home"))
+    if (!!strcmp(result, "e,temp-,-home")) {
+        free(result);
         return "csv with embedded subst failed";
+    }
     free(result);
 
     return 0;

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/16674f44/tests/tool_test.c
----------------------------------------------------------------------
diff --git a/tests/tool_test.c b/tests/tool_test.c
index a8a894b..b0d07f3 100644
--- a/tests/tool_test.c
+++ b/tests/tool_test.c
@@ -256,30 +256,69 @@ static char* test_bitmask(void *context)
 
     bm = qd_bitmask(0);
     if (!bm)                             return "Can't allocate a bit mask";
-    if (qd_bitmask_first_set(bm, &num))  return "Expected no first set bit";
-    if (qd_bitmask_cardinality(bm) != 0) return "Expected cardinality == 0";
+    if (qd_bitmask_first_set(bm, &num)) {
+        qd_bitmask_free(bm);
+        return "Expected no first set bit";
+    }
+    if (qd_bitmask_cardinality(bm) != 0) {
+        qd_bitmask_free(bm);
+        return "Expected cardinality == 0";
+    }
 
     old = qd_bitmask_set_bit(bm, 3);
-    if (old)                             return "Expected old value to be zero";
-    if (qd_bitmask_cardinality(bm) != 1) return "Expected cardinality == 1";
+    if (old) {
+        qd_bitmask_free(bm);
+        return "Expected old value to be zero";
+    }
+    if (qd_bitmask_cardinality(bm) != 1) {
+        qd_bitmask_free(bm);
+        return "Expected cardinality == 1";
+    }
     old = qd_bitmask_set_bit(bm, 3);
-    if (!old)                            return "Expected old value to be one";
+    if (!old) {
+        qd_bitmask_free(bm);
+        return "Expected old value to be one";
+    }
     qd_bitmask_set_bit(bm, 100);
-    if (qd_bitmask_cardinality(bm) != 2) return "Expected cardinality == 2";
+    if (qd_bitmask_cardinality(bm) != 2) {
+        qd_bitmask_free(bm);
+        return "Expected cardinality == 2";
+    }
 
-    if (!qd_bitmask_first_set(bm, &num)) return "Expected first set bit";
-    if (num != 3)                        return "Expected first set bit to be 3";
+    if (!qd_bitmask_first_set(bm, &num)) {
+        qd_bitmask_free(bm);
+        return "Expected first set bit";
+    }
+    if (num != 3) {
+        qd_bitmask_free(bm);
+        return "Expected first set bit to be 3";
+    }
 
     old = qd_bitmask_clear_bit(bm, num);
-    if (!old)                            return "Expected old value to be one(2)";
+    if (!old) {
+        qd_bitmask_free(bm);
+        return "Expected old value to be one(2)";
+    }
     old = qd_bitmask_clear_bit(bm, num);
-    if (old)                             return "Expected old value to be zero(2)";
+    if (old) {
+        qd_bitmask_free(bm);
+        return "Expected old value to be zero(2)";
+    }
 
-    if (!qd_bitmask_first_set(bm, &num)) return "Expected first set bit (2)";
-    if (num != 100)                      return "Expected first set bit to be 100";
+    if (!qd_bitmask_first_set(bm, &num)) {
+        qd_bitmask_free(bm);
+        return "Expected first set bit (2)";
+    }
+    if (num != 100) {
+        qd_bitmask_free(bm);
+        return "Expected first set bit to be 100";
+    }
 
     qd_bitmask_clear_bit(bm, num);
-    if (qd_bitmask_first_set(bm, &num)) return "Expected no first set bit (2)";
+    if (qd_bitmask_first_set(bm, &num)) {
+        qd_bitmask_free(bm);
+        return "Expected no first set bit (2)";
+    }
 
     qd_bitmask_set_bit(bm, 6);
     qd_bitmask_set_bit(bm, 2);
@@ -289,7 +328,10 @@ static char* test_bitmask(void *context)
     qd_bitmask_clear_bit(bm, 8);
     qd_bitmask_clear_bit(bm, 80);
 
-    if (qd_bitmask_cardinality(bm) != 4) return "Expected cardinality == 4";
+    if (qd_bitmask_cardinality(bm) != 4) {
+        qd_bitmask_free(bm);
+        return "Expected cardinality == 4";
+    }
 
     total = 0;
     count = 0;
@@ -297,8 +339,14 @@ static char* test_bitmask(void *context)
         total += num;
         count++;
     }
-    if (count != 4)  return "Expected count to be 4";
-    if (total != 82) return "Expected bit-number total to be 82";
+    if (count != 4) {
+        qd_bitmask_free(bm);
+        return "Expected count to be 4";
+    }
+    if (total != 82) {
+        qd_bitmask_free(bm);
+        return "Expected bit-number total to be 82";
+    }
 
     qd_bitmask_free(bm);
 


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


Mime
View raw message