- struct ltt_session *tmp;
-
- session_lock_list();
- tmp = session_find_by_name(SESSION1);
-
- ok(tmp != NULL,
- "Validating session: session found");
-
- if (tmp) {
- ok(tmp->kernel_session == NULL &&
- strlen(tmp->name),
+ /*
+ * Mind the order of the declaration of list_lock vs session:
+ * the session list lock must always be released _after_ the release of
+ * a session's reference (the destruction of a ref/locked_ref) to ensure
+ * since the reference's release may unpublish the session from the list of
+ * sessions.
+ */
+ const auto list_lock = lttng::sessiond::lock_session_list();
+
+ try {
+ const auto session = ltt_session::find_session(SESSION1);
+ pass("Validating session: session found");
+
+ ok(session->kernel_session == nullptr && strlen(session->name),