- notification->event = bt_event_create(event_class, packet);
- if (!notification->event) {
- BT_LIB_LOGE("Cannot create event from event class: "
- "%![event-class-]+E", event_class);
+ /*
+ * Create notification from pool _after_ we have everything
+ * (in this case, a valid event object) so that we never have an
+ * error condition with a non-NULL notification object.
+ * Otherwise:
+ *
+ * * We cannot recycle the notification on error because
+ * bt_notification_event_recycle() expects a complete
+ * notification (and the event or clock class priority map
+ * object could be unset).
+ *
+ * * We cannot destroy the notification because we would need
+ * to notify the graph (pool owner) so that it removes the
+ * notification from its notification array.
+ */
+ graph = bt_private_connection_private_notification_iterator_borrow_graph(
+ notif_iter);
+ notification = (void *) bt_notification_create_from_pool(
+ &graph->event_notif_pool, graph);
+ if (unlikely(!notification)) {
+ /* bt_notification_create_from_pool() logs errors */