diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 25558e62..9c6898d9 100644 --- a/iscsi-scst/usr/target.c +++ b/iscsi-scst/usr/target.c @@ -357,6 +357,13 @@ int target_del(u32 tid, u32 cookie) /* We might need to handle session(s) removal event(s) from the kernel */ while (handle_iscsi_events(nl_fd, false) == 0); + /* Someone else may have already freed the target object by now. */ + target = target_find_by_id(tid); + if (!target) { + log_info("%s: the target with tid = %u was already freed", __func__, tid); + return 0; + } + if (list_empty(&target->sessions_list)) break;