You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gm...@apache.org on 2016/04/08 21:00:09 UTC
qpid-dispatch git commit: DISPATCH-245 - More fixes to memory leaks
discovered by coverity. Moved code into do while loop and replaced
QD_ERROR_RET() with QD_ERROR_BREAK
Repository: qpid-dispatch
Updated Branches:
refs/heads/master ee856b3b9 -> deeb0316b
DISPATCH-245 - More fixes to memory leaks discovered by coverity. Moved code into do while loop and replaced QD_ERROR_RET() with QD_ERROR_BREAK
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/deeb0316
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/deeb0316
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/deeb0316
Branch: refs/heads/master
Commit: deeb0316b9eaa04b748d5f83d5c772e7ab9754a3
Parents: ee856b3
Author: Ganesh Murthy <gm...@redhat.com>
Authored: Fri Apr 8 14:59:36 2016 -0400
Committer: Ganesh Murthy <gm...@redhat.com>
Committed: Fri Apr 8 14:59:36 2016 -0400
----------------------------------------------------------------------
src/log.c | 21 ++-
src/message.c | 17 +-
src/router_config.c | 447 ++++++++++++++++++++++++++---------------------
3 files changed, 275 insertions(+), 210 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/deeb0316/src/log.c
----------------------------------------------------------------------
diff --git a/src/log.c b/src/log.c
index f2657e4..4cd52c8 100644
--- a/src/log.c
+++ b/src/log.c
@@ -452,19 +452,21 @@ qd_error_t qd_log_entity(qd_entity_t *entity) {
//Obtain the log_source_lock global lock
sys_mutex_lock(log_source_lock);
+ char* module = 0;
+ char *output = 0;
+ char *enable = 0;
+
do {
- char* module = qd_entity_get_string(entity, "module");
+ module = qd_entity_get_string(entity, "module");
QD_ERROR_BREAK();
qd_log_source_t *src = qd_log_source_lh(module); /* The original(already existing) log source */
- free(module);
if (qd_entity_has(entity, "output")) {
- char* output = qd_entity_get_string(entity, "output");
+ output = qd_entity_get_string(entity, "output");
QD_ERROR_BREAK();
log_sink_t* sink = log_sink_lh(output);
- free(output);
QD_ERROR_BREAK();
log_sink_free_lh(src->sink); /* DEFAULT source may already have a sink, so free that sink first */
@@ -475,9 +477,9 @@ qd_error_t qd_log_entity(qd_entity_t *entity) {
}
if (qd_entity_has(entity, "enable")) {
- char *enable = qd_entity_get_string(entity, "enable");
+ enable = qd_entity_get_string(entity, "enable");
+ QD_ERROR_BREAK();
src->mask = enable_mask(enable);
- free(enable);
}
QD_ERROR_BREAK();
@@ -491,6 +493,13 @@ qd_error_t qd_log_entity(qd_entity_t *entity) {
} while(0);
+ if (module)
+ free(module);
+ if (output)
+ free(output);
+ if (enable)
+ free(enable);
+
sys_mutex_unlock(log_source_lock);
return qd_error_code();
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/deeb0316/src/message.c
----------------------------------------------------------------------
diff --git a/src/message.c b/src/message.c
index c5dc028..11e993c 100644
--- a/src/message.c
+++ b/src/message.c
@@ -100,14 +100,15 @@ static const char REPR_END[] = "}\0";
/* TODO aconway 2014-05-13: more detailed message representation. */
char* qd_message_repr(qd_message_t *msg, char* buffer, size_t len) {
- qd_message_check(msg, QD_DEPTH_BODY);
- char *begin = buffer;
- char *end = buffer + len - sizeof(REPR_END); /* Save space for ending */
- aprintf(&begin, end, "Message{", msg);
- copy_field(msg, QD_FIELD_TO, INT_MAX, "to='", "'", &begin, end);
- copy_field(msg, QD_FIELD_REPLY_TO, INT_MAX, " reply-to='", "'", &begin, end);
- copy_field(msg, QD_FIELD_BODY, 16, " body='", "'", &begin, end);
- aprintf(&begin, end, "%s", REPR_END); /* We saved space at the beginning. */
+ if (qd_message_check(msg, QD_DEPTH_BODY)) {
+ char *begin = buffer;
+ char *end = buffer + len - sizeof(REPR_END); /* Save space for ending */
+ aprintf(&begin, end, "Message{", msg);
+ copy_field(msg, QD_FIELD_TO, INT_MAX, "to='", "'", &begin, end);
+ copy_field(msg, QD_FIELD_REPLY_TO, INT_MAX, " reply-to='", "'", &begin, end);
+ copy_field(msg, QD_FIELD_BODY, 16, " body='", "'", &begin, end);
+ aprintf(&begin, end, "%s", REPR_END); /* We saved space at the beginning. */
+ }
return buffer;
}
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/deeb0316/src/router_config.c
----------------------------------------------------------------------
diff --git a/src/router_config.c b/src/router_config.c
index cae7e82..c512a31 100644
--- a/src/router_config.c
+++ b/src/router_config.c
@@ -188,165 +188,205 @@ qd_error_t qd_router_configure_lrp(qd_router_t *router, qd_entity_t *entity)
qd_log(router->log_source, QD_LOG_WARNING, "linkRoutePrefix configuration is deprecated, switch to using linkRoute instead.");
}
- char *prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_RET();
- char *connector = qd_entity_get_string(entity, "connector"); QD_ERROR_RET();
- char *direction = qd_entity_get_string(entity, "dir"); QD_ERROR_RET();
+ char *prefix = 0;
+ char *connector = 0;
+ char *direction = 0;
- if (strcmp("in", direction) == 0 || strcmp("both", direction) == 0)
- qd_router_add_link_route(router->router_core, prefix, connector, "in");
+ do {
+ prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_BREAK();
+ connector = qd_entity_get_string(entity, "connector"); QD_ERROR_BREAK();
+ direction = qd_entity_get_string(entity, "dir"); QD_ERROR_BREAK();
- if (strcmp("out", direction) == 0 || strcmp("both", direction) == 0)
- qd_router_add_link_route(router->router_core, prefix, connector, "out");
+ if (strcmp("in", direction) == 0 || strcmp("both", direction) == 0)
+ qd_router_add_link_route(router->router_core, prefix, connector, "in");
+
+ if (strcmp("out", direction) == 0 || strcmp("both", direction) == 0)
+ qd_router_add_link_route(router->router_core, prefix, connector, "out");
+
+ } while (0);
+
+ if (prefix)
+ free(prefix);
+ if (connector)
+ free(connector);
+ if (direction)
+ free(direction);
- free(prefix);
- free(connector);
- free(direction);
return qd_error_code();
}
qd_error_t qd_router_configure_address(qd_router_t *router, qd_entity_t *entity)
{
- char *name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_RET();
- char *prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_RET();
- char *distrib = qd_entity_opt_string(entity, "distribution", 0); QD_ERROR_RET();
- bool waypoint = qd_entity_opt_bool(entity, "waypoint", false); QD_ERROR_RET();
- long in_phase = qd_entity_opt_long(entity, "ingressPhase", -1); QD_ERROR_RET();
- long out_phase = qd_entity_opt_long(entity, "egressPhase", -1); QD_ERROR_RET();
+ char *name = 0;
+ char *prefix = 0;
+ char *distrib = 0;
- //
- // Formulate this configuration create it through the core management API.
- //
- qd_composed_field_t *body = qd_compose_subfield(0);
- qd_compose_start_map(body);
+ do {
+ name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_BREAK();
+ prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_BREAK();
+ distrib = qd_entity_opt_string(entity, "distribution", 0); QD_ERROR_BREAK();
- if (name) {
- qd_compose_insert_string(body, "name");
- qd_compose_insert_string(body, name);
- }
+ bool waypoint = qd_entity_opt_bool(entity, "waypoint", false);
+ long in_phase = qd_entity_opt_long(entity, "ingressPhase", -1);
+ long out_phase = qd_entity_opt_long(entity, "egressPhase", -1);
- if (prefix) {
- qd_compose_insert_string(body, "prefix");
- qd_compose_insert_string(body, prefix);
- }
+ //
+ // Formulate this configuration create it through the core management API.
+ //
+ qd_composed_field_t *body = qd_compose_subfield(0);
+ qd_compose_start_map(body);
- if (distrib) {
- qd_compose_insert_string(body, "distribution");
- qd_compose_insert_string(body, distrib);
- }
+ if (name) {
+ qd_compose_insert_string(body, "name");
+ qd_compose_insert_string(body, name);
+ }
- qd_compose_insert_string(body, "waypoint");
- qd_compose_insert_bool(body, waypoint);
+ if (prefix) {
+ qd_compose_insert_string(body, "prefix");
+ qd_compose_insert_string(body, prefix);
+ }
- if (in_phase >= 0) {
- qd_compose_insert_string(body, "ingressPhase");
- qd_compose_insert_int(body, in_phase);
- }
+ if (distrib) {
+ qd_compose_insert_string(body, "distribution");
+ qd_compose_insert_string(body, distrib);
+ }
- if (out_phase >= 0) {
- qd_compose_insert_string(body, "egressPhase");
- qd_compose_insert_int(body, out_phase);
- }
+ qd_compose_insert_string(body, "waypoint");
+ qd_compose_insert_bool(body, waypoint);
- qd_compose_end_map(body);
+ if (in_phase >= 0) {
+ qd_compose_insert_string(body, "ingressPhase");
+ qd_compose_insert_int(body, in_phase);
+ }
- int length = 0;
- qd_buffer_list_t buffers;
+ if (out_phase >= 0) {
+ qd_compose_insert_string(body, "egressPhase");
+ qd_compose_insert_int(body, out_phase);
+ }
- qd_compose_take_buffers(body, &buffers);
- qd_compose_free(body);
+ qd_compose_end_map(body);
- qd_buffer_t *buf = DEQ_HEAD(buffers);
- while (buf) {
- length += qd_buffer_size(buf);
- buf = DEQ_NEXT(buf);
- }
+ int length = 0;
+ qd_buffer_list_t buffers;
- qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
- qd_parsed_field_t *in_body = qd_parse(iter);
- qd_field_iterator_free(iter);
+ qd_compose_take_buffers(body, &buffers);
+ qd_compose_free(body);
- qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_ADDRESS, 0, in_body, 0);
-
- free(name);
- free(prefix);
- free(distrib);
-
- return qd_error_code();
-}
-
-
-qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *entity)
-{
- char *name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_RET();
- char *prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_RET();
- char *container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_RET();
- char *c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_RET();
- char *distrib = qd_entity_opt_string(entity, "distribution", 0); QD_ERROR_RET();
- char *dir = qd_entity_opt_string(entity, "dir", 0); QD_ERROR_RET();
-
- //
- // Formulate this configuration as a route and create it through the core management API.
- //
- qd_composed_field_t *body = qd_compose_subfield(0);
- qd_compose_start_map(body);
-
- if (name) {
- qd_compose_insert_string(body, "name");
- qd_compose_insert_string(body, name);
- }
-
- if (prefix) {
- qd_compose_insert_string(body, "prefix");
- qd_compose_insert_string(body, prefix);
- }
-
- if (container) {
- qd_compose_insert_string(body, "containerId");
- qd_compose_insert_string(body, container);
- }
+ qd_buffer_t *buf = DEQ_HEAD(buffers);
+ while (buf) {
+ length += qd_buffer_size(buf);
+ buf = DEQ_NEXT(buf);
+ }
- if (c_name) {
- qd_compose_insert_string(body, "connection");
- qd_compose_insert_string(body, c_name);
- }
+ qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
+ qd_parsed_field_t *in_body = qd_parse(iter);
+ qd_field_iterator_free(iter);
- if (distrib) {
- qd_compose_insert_string(body, "distribution");
- qd_compose_insert_string(body, distrib);
- }
+ qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_ADDRESS, 0, in_body, 0);
- if (dir) {
- qd_compose_insert_string(body, "dir");
- qd_compose_insert_string(body, dir);
- }
- qd_compose_end_map(body);
+ } while(0);
- int length = 0;
- qd_buffer_list_t buffers;
-
- qd_compose_take_buffers(body, &buffers);
- qd_compose_free(body);
+ if (name)
+ free(name);
+ if (prefix)
+ free(prefix);
+ if (distrib)
+ free(distrib);
- qd_buffer_t *buf = DEQ_HEAD(buffers);
- while (buf) {
- length += qd_buffer_size(buf);
- buf = DEQ_NEXT(buf);
- }
+ return qd_error_code();
+}
- qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
- qd_parsed_field_t *in_body = qd_parse(iter);
- qd_field_iterator_free(iter);
- qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_LINK_ROUTE, 0, in_body, 0);
+qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *entity)
+{
- free(name);
- free(prefix);
- free(container);
- free(c_name);
- free(distrib);
- free(dir);
+ char *name = 0;
+ char *prefix = 0;
+ char *container = 0;
+ char *c_name = 0;
+ char *distrib = 0;
+ char *dir = 0;
+
+ do {
+ name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_BREAK();
+ prefix = qd_entity_get_string(entity, "prefix"); QD_ERROR_BREAK();
+ container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_BREAK();
+ c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_BREAK();
+ distrib = qd_entity_opt_string(entity, "distribution", 0); QD_ERROR_BREAK();
+ dir = qd_entity_opt_string(entity, "dir", 0); QD_ERROR_BREAK();
+
+ //
+ // Formulate this configuration as a route and create it through the core management API.
+ //
+ qd_composed_field_t *body = qd_compose_subfield(0);
+ qd_compose_start_map(body);
+
+ if (name) {
+ qd_compose_insert_string(body, "name");
+ qd_compose_insert_string(body, name);
+ }
+
+ if (prefix) {
+ qd_compose_insert_string(body, "prefix");
+ qd_compose_insert_string(body, prefix);
+ }
+
+ if (container) {
+ qd_compose_insert_string(body, "containerId");
+ qd_compose_insert_string(body, container);
+ }
+
+ if (c_name) {
+ qd_compose_insert_string(body, "connection");
+ qd_compose_insert_string(body, c_name);
+ }
+
+ if (distrib) {
+ qd_compose_insert_string(body, "distribution");
+ qd_compose_insert_string(body, distrib);
+ }
+
+ if (dir) {
+ qd_compose_insert_string(body, "dir");
+ qd_compose_insert_string(body, dir);
+ }
+
+ qd_compose_end_map(body);
+
+ int length = 0;
+ qd_buffer_list_t buffers;
+
+ qd_compose_take_buffers(body, &buffers);
+ qd_compose_free(body);
+
+ qd_buffer_t *buf = DEQ_HEAD(buffers);
+ while (buf) {
+ length += qd_buffer_size(buf);
+ buf = DEQ_NEXT(buf);
+ }
+
+ qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
+ qd_parsed_field_t *in_body = qd_parse(iter);
+ qd_field_iterator_free(iter);
+
+ qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_LINK_ROUTE, 0, in_body, 0);
+
+ } while(0);
+
+ if (name)
+ free(name);
+ if (prefix)
+ free(prefix);
+ if (container)
+ free(container);
+ if (c_name)
+ free(c_name);
+ if (distrib)
+ free(distrib);
+ if (dir)
+ free(dir);
return qd_error_code();
}
@@ -354,74 +394,89 @@ qd_error_t qd_router_configure_link_route(qd_router_t *router, qd_entity_t *enti
qd_error_t qd_router_configure_auto_link(qd_router_t *router, qd_entity_t *entity)
{
- char *name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_RET();
- char *addr = qd_entity_get_string(entity, "addr"); QD_ERROR_RET();
- char *dir = qd_entity_get_string(entity, "dir"); QD_ERROR_RET();
- long phase = qd_entity_opt_long(entity, "phase", -1); QD_ERROR_RET();
- char *container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_RET();
- char *c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_RET();
-
- //
- // Formulate this configuration as a route and create it through the core management API.
- //
- qd_composed_field_t *body = qd_compose_subfield(0);
- qd_compose_start_map(body);
-
- if (name) {
- qd_compose_insert_string(body, "name");
- qd_compose_insert_string(body, name);
- }
-
- if (addr) {
- qd_compose_insert_string(body, "addr");
- qd_compose_insert_string(body, addr);
- }
-
- if (dir) {
- qd_compose_insert_string(body, "dir");
- qd_compose_insert_string(body, dir);
- }
-
- if (phase >= 0) {
- qd_compose_insert_string(body, "phase");
- qd_compose_insert_int(body, phase);
- }
-
- if (container) {
- qd_compose_insert_string(body, "containerId");
- qd_compose_insert_string(body, container);
- }
-
- if (c_name) {
- qd_compose_insert_string(body, "connection");
- qd_compose_insert_string(body, c_name);
- }
-
- qd_compose_end_map(body);
-
- int length = 0;
- qd_buffer_list_t buffers;
-
- qd_compose_take_buffers(body, &buffers);
- qd_compose_free(body);
-
- qd_buffer_t *buf = DEQ_HEAD(buffers);
- while (buf) {
- length += qd_buffer_size(buf);
- buf = DEQ_NEXT(buf);
- }
-
- qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
- qd_parsed_field_t *in_body = qd_parse(iter);
- qd_field_iterator_free(iter);
-
- qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_AUTO_LINK, 0, in_body, 0);
-
- free(name);
- free(addr);
- free(dir);
- free(container);
- free(c_name);
+ char *name = 0;
+ char *addr = 0;
+ char *dir = 0;
+ char *container = 0;
+ char *c_name = 0;
+
+ do {
+ name = qd_entity_opt_string(entity, "name", 0); QD_ERROR_BREAK();
+ addr = qd_entity_get_string(entity, "addr"); QD_ERROR_BREAK();
+ dir = qd_entity_get_string(entity, "dir"); QD_ERROR_BREAK();
+ container = qd_entity_opt_string(entity, "containerId", 0); QD_ERROR_BREAK();
+ c_name = qd_entity_opt_string(entity, "connection", 0); QD_ERROR_BREAK();
+ long phase = qd_entity_opt_long(entity, "phase", -1); QD_ERROR_BREAK();
+
+ //
+ // Formulate this configuration as a route and create it through the core management API.
+ //
+ qd_composed_field_t *body = qd_compose_subfield(0);
+ qd_compose_start_map(body);
+
+ if (name) {
+ qd_compose_insert_string(body, "name");
+ qd_compose_insert_string(body, name);
+ }
+
+ if (addr) {
+ qd_compose_insert_string(body, "addr");
+ qd_compose_insert_string(body, addr);
+ }
+
+ if (dir) {
+ qd_compose_insert_string(body, "dir");
+ qd_compose_insert_string(body, dir);
+ }
+
+ if (phase >= 0) {
+ qd_compose_insert_string(body, "phase");
+ qd_compose_insert_int(body, phase);
+ }
+
+ if (container) {
+ qd_compose_insert_string(body, "containerId");
+ qd_compose_insert_string(body, container);
+ }
+
+ if (c_name) {
+ qd_compose_insert_string(body, "connection");
+ qd_compose_insert_string(body, c_name);
+ }
+
+ qd_compose_end_map(body);
+
+ int length = 0;
+ qd_buffer_list_t buffers;
+
+ qd_compose_take_buffers(body, &buffers);
+ qd_compose_free(body);
+
+ qd_buffer_t *buf = DEQ_HEAD(buffers);
+ while (buf) {
+ length += qd_buffer_size(buf);
+ buf = DEQ_NEXT(buf);
+ }
+
+ qd_field_iterator_t *iter = qd_field_iterator_buffer(DEQ_HEAD(buffers), 0, length);
+ qd_parsed_field_t *in_body = qd_parse(iter);
+ qd_field_iterator_free(iter);
+
+ qdr_manage_create(router->router_core, 0, QD_ROUTER_CONFIG_AUTO_LINK, 0, in_body, 0);
+
+ } while (0);
+
+
+ if (name)
+ free(name);
+ if (addr)
+ free(addr);
+ if (dir)
+ free(dir);
+ if (container)
+ free(container);
+ if (c_name)
+ free(c_name);
return qd_error_code();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org