From 0c2fd8e564463a67efba50537df5e9c082068c8f Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Sat, 2 Jul 2016 01:42:49 +0000 Subject: [PATCH] iscsi-scst: handle a case in target_del() where the target was already freed target_del() calls handle_iscsi_events() which may recursively call target_del(). The 1st target_del() may resume its execution after the target object was already freed. Signed-off-by: Erez Zilber git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@6908 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/usr/target.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iscsi-scst/usr/target.c b/iscsi-scst/usr/target.c index 25558e629..9c6898d98 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;