qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1571: c++: fix listener leak
Date Sat, 07 Oct 2017 00:32:59 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 3e4b963a6 -> bb7b82615


PROTON-1571: c++: fix listener leak

Fix  epoll proactor leak when listening on a port that is not available.


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

Branch: refs/heads/master
Commit: bb7b82615c129e56b8bc94c64914436961fb67a2
Parents: 3e4b963
Author: Alan Conway <aconway@redhat.com>
Authored: Fri Oct 6 17:48:54 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Fri Oct 6 20:18:21 2017 -0400

----------------------------------------------------------------------
 proton-c/src/proactor/epoll.c |  3 ++-
 proton-c/src/tests/proactor.c | 20 +++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/bb7b8261/proton-c/src/proactor/epoll.c
----------------------------------------------------------------------
diff --git a/proton-c/src/proactor/epoll.c b/proton-c/src/proactor/epoll.c
index c06c5d2..d739ab1 100644
--- a/proton-c/src/proactor/epoll.c
+++ b/proton-c/src/proactor/epoll.c
@@ -1406,7 +1406,8 @@ void pn_proactor_listen(pn_proactor_t *p, pn_listener_t *l, const char
*addr, in
   bool notify = wake(&l->context);
 
   if (l->psockets_size == 0) { /* All failed, create dummy socket with an error */
-    l->psockets = (psocket_t*)calloc(sizeof(psocket_t), 1);
+    l->psockets = (psocket_t*)realloc(l->psockets, sizeof(psocket_t));
+    memset(l->psockets, 0, sizeof(psocket_t));
     psocket_init(l->psockets, p, l, addr);
     if (gai_err) {
       psocket_gai_error(l->psockets, gai_err, "listen on");

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/bb7b8261/proton-c/src/tests/proactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/proactor.c b/proton-c/src/tests/proactor.c
index 38ee46a..245284c 100644
--- a/proton-c/src/tests/proactor.c
+++ b/proton-c/src/tests/proactor.c
@@ -575,7 +575,6 @@ static void test_inactive(test_t *t) {
 static void test_errors(test_t *t) {
   test_proactor_t tps[] =  { test_proactor(t, open_wake_handler), test_proactor(t, listen_handler)
};
   pn_proactor_t *client = tps[0].proactor, *server = tps[1].proactor;
-  test_port_t port = test_port(localhost);          /* Hold a port */
 
   /* Invalid connect/listen service name */
   pn_connection_t *c = pn_connection();
@@ -584,8 +583,7 @@ static void test_errors(test_t *t) {
   TEST_COND_DESC(t, "xxx", last_condition);
   TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, TEST_PROACTORS_RUN(tps));
 
-  pn_listener_t *l = pn_listener();
-  pn_proactor_listen(server, l, "127.0.0.1:xxx", 1);
+  pn_proactor_listen(server, pn_listener(), "127.0.0.1:xxx", 1);
   TEST_ETYPE_EQUAL(t, PN_LISTENER_OPEN, TEST_PROACTORS_RUN(tps));
   TEST_ETYPE_EQUAL(t, PN_LISTENER_CLOSE, TEST_PROACTORS_RUN(tps));
   TEST_COND_DESC(t, "xxx", last_condition);
@@ -598,13 +596,25 @@ static void test_errors(test_t *t) {
   TEST_COND_DESC(t, "nosuch", last_condition);
   TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, TEST_PROACTORS_RUN(tps));
 
-  l = pn_listener();
-  pn_proactor_listen(server, l, "nosuch.example.com:", 1);
+  pn_proactor_listen(server, pn_listener(), "nosuch.example.com:", 1);
   TEST_ETYPE_EQUAL(t, PN_LISTENER_OPEN, TEST_PROACTORS_RUN(tps));
   TEST_ETYPE_EQUAL(t, PN_LISTENER_CLOSE, TEST_PROACTORS_RUN(tps));
   TEST_COND_DESC(t, "nosuch", last_condition);
   TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, TEST_PROACTORS_RUN(tps));
 
+  /* Listen on a port already in use */
+  test_port_t port = test_port(localhost);
+  pn_listener_t *l = pn_listener();
+  pn_proactor_listen(server, l, port.host_port, 1);
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_OPEN, TEST_PROACTORS_RUN(tps));
+  pn_proactor_listen(server, pn_listener(), port.host_port, 1); /* Busy */
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_OPEN, TEST_PROACTORS_RUN(tps));
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_CLOSE, TEST_PROACTORS_RUN(tps));
+  TEST_COND_NAME(t, "proton:io", last_condition);
+  pn_listener_close(l);
+  TEST_ETYPE_EQUAL(t, PN_LISTENER_CLOSE, TEST_PROACTORS_RUN(tps));
+  TEST_ETYPE_EQUAL(t, PN_PROACTOR_INACTIVE, TEST_PROACTORS_RUN(tps));
+
   /* Connect with no listener */
   c = pn_connection();
   pn_proactor_connect(client, c, port.host_port);


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


Mime
View raw message