Fix: cancel a notif. iter. finalized during its "next" method
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 5 Jun 2017 19:18:11 +0000 (15:18 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 21:02:58 +0000 (17:02 -0400)
It is possible that the user's "next" method, somehow, cancels its own
notification iterator. This can happen, for example, when the user's
method removes the port on which there's the connection from which the
notification iterator was created. In this case, said connection is
ended, and all its notification iterators are finalized.

In ensure_queue_has_notifications(), after calling the user's "next"
method, if there's no error, we check if the notification iterator is
finalized. If so, we return the BT_NOTIFICATION_ITERATOR_STATUS_CANCELED
status directly.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
lib/graph/iterator.c

index 70930bc75c1c68a54a3af5249a2d5dbb8683a22e..07eaa1fd146d42d8702c897ec6020bf0f95a46c1 100644 (file)
@@ -1550,6 +1550,32 @@ enum bt_notification_iterator_status ensure_queue_has_notifications(
                        goto end;
                }
 
+               if (iterator->state == BT_NOTIFICATION_ITERATOR_STATE_FINALIZED ||
+                               iterator->state == BT_NOTIFICATION_ITERATOR_STATE_FINALIZED_AND_ENDED) {
+                       /*
+                        * The user's "next" method, somehow, cancelled
+                        * its own notification iterator. This can
+                        * happen, for example, when the user's method
+                        * removes the port on which there's the
+                        * connection from which the iterator was
+                        * created. In this case, said connection is
+                        * ended, and all its notification iterators are
+                        * finalized.
+                        *
+                        * Only bt_put() the returned notification if
+                        * the status is
+                        * BT_NOTIFICATION_ITERATOR_STATUS_OK because
+                        * otherwise this field could be garbage.
+                        */
+                       if (next_return.status ==
+                                       BT_NOTIFICATION_ITERATOR_STATUS_OK) {
+                               bt_put(next_return.notification);
+                       }
+
+                       status = BT_NOTIFICATION_ITERATOR_STATUS_CANCELED;
+                       goto end;
+               }
+
                switch (next_return.status) {
                case BT_NOTIFICATION_ITERATOR_STATUS_END:
                        ret = handle_end(iterator);
This page took 0.025495 seconds and 4 git commands to generate.