qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject svn commit: r1672734 - in /qpid/dispatch/trunk: include/qpid/dispatch/container.h src/container.c src/router_node.c src/router_private.h
Date Fri, 10 Apr 2015 19:35:45 GMT
Author: kgiusti
Date: Fri Apr 10 19:35:45 2015
New Revision: 1672734

URL: http://svn.apache.org/r1672734
Log:
DISPATCH-133: fix stale pointer references (valgrind errors)

Modified:
    qpid/dispatch/trunk/include/qpid/dispatch/container.h
    qpid/dispatch/trunk/src/container.c
    qpid/dispatch/trunk/src/router_node.c
    qpid/dispatch/trunk/src/router_private.h

Modified: qpid/dispatch/trunk/include/qpid/dispatch/container.h
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/include/qpid/dispatch/container.h?rev=1672734&r1=1672733&r2=1672734&view=diff
==============================================================================
--- qpid/dispatch/trunk/include/qpid/dispatch/container.h (original)
+++ qpid/dispatch/trunk/include/qpid/dispatch/container.h Fri Apr 10 19:35:45 2015
@@ -198,6 +198,7 @@ bool qd_delivery_settled(qd_delivery_t *
 bool qd_delivery_disp_changed(qd_delivery_t *delivery);
 uint64_t qd_delivery_disp(qd_delivery_t *delivery);
 qd_link_t *qd_delivery_link(qd_delivery_t *delivery);
+void qd_link_free_LH(qd_link_t *link);
 
 ///@}
 #endif

Modified: qpid/dispatch/trunk/src/container.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/container.c?rev=1672734&r1=1672733&r2=1672734&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/container.c (original)
+++ qpid/dispatch/trunk/src/container.c Fri Apr 10 19:35:45 2015
@@ -49,20 +49,9 @@ DEQ_DECLARE(qd_node_t, qd_node_list_t);
 ALLOC_DECLARE(qd_node_t);
 ALLOC_DEFINE(qd_node_t);
 
-/** Encapsulates a proton link for sending and receiving messages */
-struct qd_link_t {
-    pn_session_t *pn_sess;
-    pn_link_t    *pn_link;
-    void         *context;
-    qd_node_t    *node;
-    bool          drain_mode;
-};
-
-ALLOC_DECLARE(qd_link_t);
-ALLOC_DEFINE(qd_link_t);
-
 /** Encapsulates a proton message delivery */
 struct qd_delivery_t {
+    DEQ_LINKS(qd_delivery_t);
     pn_delivery_t *pn_delivery;
     qd_delivery_t *peer;
     void          *context;
@@ -71,9 +60,23 @@ struct qd_delivery_t {
     int            in_fifo;
     bool           pending_delete;
 };
-
 ALLOC_DECLARE(qd_delivery_t);
 ALLOC_DEFINE(qd_delivery_t);
+DEQ_DECLARE(qd_delivery_t, qd_delivery_list_t);
+
+
+/** Encapsulates a proton link for sending and receiving messages */
+struct qd_link_t {
+    pn_session_t       *pn_sess;
+    pn_link_t          *pn_link;
+    void               *context;
+    qd_node_t          *node;
+    bool               drain_mode;
+    qd_delivery_list_t deliveries;
+};
+
+ALLOC_DECLARE(qd_link_t);
+ALLOC_DEFINE(qd_link_t);
 
 
 typedef struct qdc_node_type_t {
@@ -133,6 +136,7 @@ static void setup_outgoing_link(qd_conta
     link->context    = 0;
     link->node       = node;
     link->drain_mode = pn_link_get_drain(pn_link);
+    DEQ_INIT(link->deliveries);
 
     pn_link_set_context(pn_link, link);
     node->ntype->outgoing_handler(node->context, link);
@@ -178,6 +182,7 @@ static void setup_incoming_link(qd_conta
     link->context    = 0;
     link->node       = node;
     link->drain_mode = pn_link_get_drain(pn_link);
+    DEQ_INIT(link->deliveries);
 
     pn_link_set_context(pn_link, link);
     node->ntype->incoming_handler(node->context, link);
@@ -219,6 +224,7 @@ static void do_receive(pn_delivery_t *pn
         if (node) {
             if (!delivery) {
                 delivery = new_qd_delivery_t();
+                DEQ_ITEM_INIT(delivery);
                 delivery->pn_delivery    = pnd;
                 delivery->peer           = 0;
                 delivery->context        = 0;
@@ -226,6 +232,7 @@ static void do_receive(pn_delivery_t *pn
                 delivery->link           = link;
                 delivery->in_fifo        = 0;
                 delivery->pending_delete = false;
+                DEQ_INSERT_TAIL(link->deliveries, delivery);
                 pn_delivery_set_context(pnd, delivery);
             }
 
@@ -241,6 +248,7 @@ static void do_receive(pn_delivery_t *pn
     pn_link_flow(pn_link, 1);
     pn_delivery_update(pnd, PN_REJECTED);
     pn_delivery_settle(pnd);
+    if (delivery) delivery->pn_delivery = 0;
 }
 
 
@@ -391,7 +399,6 @@ static int process_handler(qd_container_
         case PN_LINK_FINAL :
             pn_link = pn_event_link(event);
             qd_link = (qd_link_t*) pn_link_get_context(pn_link);
-            free_qd_link_t(qd_link);
             break;
 
         case PN_LINK_FLOW :
@@ -675,6 +682,7 @@ qd_link_t *qd_link(qd_node_t *node, qd_c
     link->context    = node->context;
     link->node       = node;
     link->drain_mode = pn_link_get_drain(link->pn_link);
+    DEQ_INIT(link->deliveries);
 
     pn_link_set_context(link->pn_link, link);
 
@@ -684,9 +692,14 @@ qd_link_t *qd_link(qd_node_t *node, qd_c
 }
 
 
-void qd_link_free(qd_link_t *link)
+void qd_link_free_LH(qd_link_t *link)
 {
     if (!link) return;
+    qd_delivery_t *d = DEQ_HEAD(link->deliveries);
+    while (d) {
+        qd_delivery_free_LH(d, 0);  // removes itself from list
+        d = DEQ_HEAD(link->deliveries);
+    }
     free_qd_link_t(link);
 }
 
@@ -849,6 +862,7 @@ qd_delivery_t *qd_delivery(qd_link_t *li
         return 0;
 
     qd_delivery_t *delivery = new_qd_delivery_t();
+    DEQ_ITEM_INIT(delivery);
     delivery->pn_delivery    = pnd;
     delivery->peer           = 0;
     delivery->context        = 0;
@@ -856,6 +870,7 @@ qd_delivery_t *qd_delivery(qd_link_t *li
     delivery->link           = link;
     delivery->in_fifo        = 0;
     delivery->pending_delete = false;
+    DEQ_INSERT_TAIL(link->deliveries, delivery);
     pn_delivery_set_context(pnd, delivery);
 
     return delivery;
@@ -883,8 +898,14 @@ void qd_delivery_free_LH(qd_delivery_t *
         delivery->pn_delivery = 0;
     }
 
-    assert(!delivery->peer);
-
+    //assert(!delivery->peer);
+    if (delivery->peer)
+        qd_delivery_unlink_LH(delivery);
+
+    if (delivery->link) {
+        DEQ_REMOVE(delivery->link->deliveries, delivery);
+        delivery->link = 0;
+    }
     if (delivery->in_fifo)
         delivery->pending_delete = true;
     else {

Modified: qpid/dispatch/trunk/src/router_node.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_node.c?rev=1672734&r1=1672733&r2=1672734&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_node.c (original)
+++ qpid/dispatch/trunk/src/router_node.c Fri Apr 10 19:35:45 2015
@@ -380,6 +380,50 @@ static qd_address_t *router_lookup_termi
 }
 
 
+
+void qd_router_link_free_LH(qd_router_link_t *rlink)
+{
+    qd_link_t *link = rlink->link;
+    if (link) {
+        qd_link_set_context(link, 0);
+        qd_link_free_LH(link);
+        rlink->link = 0;
+    }
+
+    if (rlink->target)
+        free(rlink->target);
+
+    assert(rlink->ref == 0);
+
+    qd_routed_event_t      *re;
+
+    re = DEQ_HEAD(rlink->event_fifo);
+    while (re) {
+        DEQ_REMOVE_HEAD(rlink->event_fifo);
+        if (re->delivery && qd_delivery_fifo_exit_LH(re->delivery)) {
+            qd_delivery_unlink_LH(re->delivery);
+            qd_delivery_free_LH(re->delivery, re->disposition);
+        }
+        free_qd_routed_event_t(re);
+        re = DEQ_HEAD(rlink->event_fifo);
+    }
+
+    re = DEQ_HEAD(rlink->msg_fifo);
+    while (re) {
+        DEQ_REMOVE_HEAD(rlink->msg_fifo);
+        if (re->delivery)
+            qd_delivery_fifo_exit_LH(re->delivery);
+        // we can't delete this delivery (it belongs to the receive link)
+        if (re->message)
+            qd_message_free(re->message);
+        free_qd_routed_event_t(re);
+        re = DEQ_HEAD(rlink->msg_fifo);
+    }
+
+    free_qd_router_link_t(rlink);
+}
+
+
 /**
  * Outgoing Link Writable Handler
  */
@@ -1546,10 +1590,12 @@ static int router_link_detach_handler(vo
     }
 
     //
-    // Remove the link from the master list-of-links.
+    // Remove the link from the master list-of-links and deallocate
     //
     DEQ_REMOVE(router->links, rlink);
     qd_entity_cache_remove(QD_ROUTER_LINK_TYPE, rlink);
+    qd_router_link_free_LH(rlink);
+
     sys_mutex_unlock(router->lock);
 
     //
@@ -1557,10 +1603,6 @@ static int router_link_detach_handler(vo
     //
     qd_router_check_addr(router, oaddr, 1);
 
-    if (rlink->target)
-        free(rlink->target);
-    free_qd_router_link_t(rlink);
-
     //
     // If we lost the link to a neighbor router, notify the route engine so it doesn't
     // have to wait for the HELLO timeout to expire.

Modified: qpid/dispatch/trunk/src/router_private.h
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_private.h?rev=1672734&r1=1672733&r2=1672734&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_private.h (original)
+++ qpid/dispatch/trunk/src/router_private.h Fri Apr 10 19:35:45 2015
@@ -91,6 +91,7 @@ struct qd_router_link_t {
 
 ALLOC_DECLARE(qd_router_link_t);
 DEQ_DECLARE(qd_router_link_t, qd_router_link_list_t);
+void qd_router_link_free_LH(qd_router_link_t *);
 
 struct qd_router_node_t {
     DEQ_LINKS(qd_router_node_t);



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


Mime
View raw message