You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/04/05 18:18:53 UTC

qpid-dispatch git commit: DISPATCH-739: Fix more test leaks - unit tests are valgrind clean

Repository: qpid-dispatch
Updated Branches:
  refs/heads/master 2d3b974ae -> ae348d0ca


DISPATCH-739: Fix more test leaks - unit tests are valgrind clean


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

Branch: refs/heads/master
Commit: ae348d0caae3a04e0d7a07e5b3f491c8da646f48
Parents: 2d3b974
Author: Alan Conway <ac...@redhat.com>
Authored: Tue Apr 4 15:40:00 2017 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Apr 5 14:16:21 2017 -0400

----------------------------------------------------------------------
 src/iterator.c     | 21 +++++++++++++--------
 tests/parse_test.c |  4 ++++
 2 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ae348d0c/src/iterator.c
----------------------------------------------------------------------
diff --git a/src/iterator.c b/src/iterator.c
index d922b29..33bb3b2 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -20,7 +20,6 @@
 #include <qpid/dispatch/iterator.h>
 #include <qpid/dispatch/ctools.h>
 #include "alloc.h"
-#include <qpid/dispatch/log.h>
 #include "message_private.h"
 #include <stdio.h>
 #include <string.h>
@@ -357,13 +356,19 @@ static void qd_iterator_free_hash_segments(qd_iterator_t *iter)
 
 void qd_iterator_set_address(const char *area, const char *router)
 {
-    my_area = (char*) malloc(strlen(area) + 2);
-    strcpy(my_area, area);
-    strcat(my_area, "/");
-
-    my_router = (char*) malloc(strlen(router) + 2);
-    strcpy(my_router, router);
-    strcat(my_router, "/");
+    static char buf[2048];     /* Static buffer, should usually be Big Enough */
+    static char *ptr = buf;
+#define FMT "%s/%c%s/", area, '\0', router /* "area/\0router/\0" */
+    size_t size = snprintf(buf, sizeof(buf), FMT);
+    if (size < sizeof(buf)) {
+        ptr = buf;
+    } else {
+        if (ptr && ptr != buf) free(ptr);
+        ptr = malloc(size + 1);
+        snprintf(buf, sizeof(buf), FMT);
+    }
+    my_area = ptr;
+    my_router = ptr + strlen(my_area) + 1;
 }
 
 

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/ae348d0c/tests/parse_test.c
----------------------------------------------------------------------
diff --git a/tests/parse_test.c b/tests/parse_test.c
index 2e04cae..bc12efd 100644
--- a/tests/parse_test.c
+++ b/tests/parse_test.c
@@ -339,6 +339,10 @@ static char *test_tracemask(void *context)
 
     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;
 }
 


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