qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject [1/2] qpid-dispatch git commit: DISPATCH-846: Fix memory leak in router config.
Date Tue, 03 Oct 2017 19:34:02 GMT
Repository: qpid-dispatch
Updated Branches:
  refs/heads/master a33dd4602 -> e69478a4e


DISPATCH-846: Fix memory leak in router config.

qd_dispatch_set_router_default_distribution() was not freeing its argument.

Also removed some other dispatch.c private configuration functions from
dispatch-private.h and made them static.


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

Branch: refs/heads/master
Commit: 96cbc159cfe9f7da3a867f759781e69e110e74e5
Parents: a33dd46
Author: Alan Conway <aconway@redhat.com>
Authored: Tue Oct 3 15:16:06 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Tue Oct 3 15:32:46 2017 -0400

----------------------------------------------------------------------
 src/dispatch.c         | 15 +++++++++++----
 src/dispatch_private.h | 12 ------------
 2 files changed, 11 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/96cbc159/src/dispatch.c
----------------------------------------------------------------------
diff --git a/src/dispatch.c b/src/dispatch.c
index 760cfdd..511f1e4 100644
--- a/src/dispatch.c
+++ b/src/dispatch.c
@@ -50,10 +50,14 @@ qd_router_t    *qd_router(qd_dispatch_t *qd, qd_router_mode_t mode, const
char *
 void            qd_router_setup_late(qd_dispatch_t *qd);
 void            qd_router_free(qd_router_t *router);
 void            qd_error_initialize();
+static void qd_dispatch_set_router_id(qd_dispatch_t *qd, char *_id);
+static void qd_dispatch_set_router_area(qd_dispatch_t *qd, char *_area);
+
 const char     *CLOSEST_DISTRIBUTION   = "closest";
 const char     *MULTICAST_DISTRIBUTION = "multicast";
 const char     *BALANCED_DISTRIBUTION  = "balanced";
 const char     *UNAVAILABLE_DISTRIBUTION = "unavailable";
+
 qd_dispatch_t *qd_dispatch(const char *python_pkgdir)
 {
     qd_dispatch_t *qd = NEW(qd_dispatch_t);
@@ -148,8 +152,8 @@ qd_error_t qd_dispatch_validate_config(const char *config_path)
 	return validation_error;
 }
 
-
-void qd_dispatch_set_router_default_distribution(qd_dispatch_t *qd, char *distribution)
+// Takes ownership of distribution string.
+static void qd_dispatch_set_router_default_distribution(qd_dispatch_t *qd, char *distribution)
 {
     if (distribution) {
         if (strcmp(distribution, MULTICAST_DISTRIBUTION) == 0)
@@ -164,6 +168,7 @@ void qd_dispatch_set_router_default_distribution(qd_dispatch_t *qd, char
*distri
     else
         // The default for the router defaultDistribution field is QD_TREATMENT_ANYCAST_BALANCED
         qd->default_treatment = QD_TREATMENT_ANYCAST_BALANCED;
+    free(distribution);
 }
 
 qd_error_t qd_dispatch_configure_router(qd_dispatch_t *qd, qd_entity_t *entity)
@@ -270,14 +275,16 @@ void qd_dispatch_set_agent(qd_dispatch_t *qd, void *agent) {
     qd->agent = agent;
 }
 
-void qd_dispatch_set_router_id(qd_dispatch_t *qd, char *_id) {
+// Takes ownership of _id
+static void qd_dispatch_set_router_id(qd_dispatch_t *qd, char *_id) {
     if (qd->router_id) {
         free(qd->router_id);
     }
     qd->router_id = _id;
 }
 
-void qd_dispatch_set_router_area(qd_dispatch_t *qd, char *_area) {
+// Takes ownership of _area
+static void qd_dispatch_set_router_area(qd_dispatch_t *qd, char *_area) {
     if (qd->router_area) {
         free(qd->router_area);
     }

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/96cbc159/src/dispatch_private.h
----------------------------------------------------------------------
diff --git a/src/dispatch_private.h b/src/dispatch_private.h
index 3fc4b9b..7e54ade 100644
--- a/src/dispatch_private.h
+++ b/src/dispatch_private.h
@@ -122,16 +122,4 @@ void qd_dispatch_unregister_entity(qd_dispatch_t *qd, void *impl);
 /** Set the agent */
 void qd_dispatch_set_agent(qd_dispatch_t *qd, void *agent);
 
-/**
- * Set a new router id, freeing the prior id string
- * TAKES OWNERSHIP OF THE POINTER PASSED TO IT
- */
-void qd_dispatch_set_router_id(qd_dispatch_t *qd, char *_id);
-
-/**
- * Set a new router area, freeing the prior area string
- * TAKES OWNERSHIP OF THE POINTER PASSED TO IT
- */
-void qd_dispatch_set_router_area(qd_dispatch_t *qd, char *_area);
-
 #endif


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


Mime
View raw message