From 65a682d27d0dfabb0e0eec5b7a8ef7bac7018dc5 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 18 Sep 2012 12:24:14 +0200 Subject: [PATCH] Fix race condition in close_msg that causes seg fault --- bacula/src/lib/message.c | 5 +++++ bacula/src/lib/parse_conf.h | 1 + 2 files changed, 6 insertions(+) diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index fc7f22ae7d..2a67c78ea6 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -517,6 +517,11 @@ void close_msg(JCR *jcr) return; } msgs->wait_not_in_use(); /* leaves fides_mutex set */ + /* Note get_closing() does not lock because we are already locked */ + if (msgs->get_closing()) { + msgs->unlock(); + return; + } msgs->set_closing(); msgs->unlock(); diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index f075df7154..0a83353567 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -145,6 +145,7 @@ public: void clear_in_use() { lock(); m_in_use=false; unlock(); } void set_in_use() { wait_not_in_use(); m_in_use=true; unlock(); } void set_closing() { m_closing=true; } + bool get_closing() { return m_closing; } void clear_closing() { lock(); m_closing=false; unlock(); } bool is_closing() { lock(); bool rtn=m_closing; unlock(); return rtn; } -- 2.39.5