From 2eb954cb34fcb956070896101df4ba78272939fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bri=C3=A8re?= Date: Mon, 3 Oct 2016 11:29:00 -0400 Subject: Skip over the mutex field when copying t_call_info data t_line::get_call_info() returns a copy of a (locked) t_call_info; copying the mutex, aside from being undefined in POSIX, returns an unexpectedly locked copy, possibly resulting in a deadlock. This fix is pretty much a copy of the one applied to t_call_record in 38bb6b7, with an added check for self-assignment. Like its predecessor, it is still susceptible to deadlock, though (as unlikely as it may be). Fixes #73 --- src/line.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/line.cpp') diff --git a/src/line.cpp b/src/line.cpp index 1eb52b8..1ba5d96 100644 --- a/src/line.cpp +++ b/src/line.cpp @@ -38,6 +38,43 @@ t_call_info::t_call_info() { clear(); } +t_call_info::t_call_info(const t_call_info& that) { + *this = that; +} + +t_call_info& t_call_info::operator=(const t_call_info& that) { + if (this != &that) { + // FIXME: This may deadlock if "a=b" and "b=a" are run in + // parallel. The proper solution would be to switch + // to std::mutex and call std::lock(this,that). + t_mutex_guard x1(that.mutex); + t_mutex_guard x2(this->mutex); + + from_uri = that.from_uri; + from_display = that.from_display; + + from_display_override = that.from_display_override; + + from_organization = that.from_organization; + to_uri = that.to_uri; + to_display = that.to_display; + to_organization = that.to_organization; + subject = that.subject; + dtmf_supported = that.dtmf_supported; + dtmf_inband = that.dtmf_inband; + dtmf_info = that.dtmf_info; + hdr_referred_by = that.hdr_referred_by; + + last_provisional_reason = that.last_provisional_reason; + + send_codec = that.send_codec; + recv_codec = that.recv_codec; + refer_supported = that.refer_supported; + } + + return *this; +} + void t_call_info::clear(void) { t_mutex_guard g(mutex); @@ -2128,7 +2165,6 @@ void t_line::retry_retrieve_succeeded(void) { } t_call_info t_line::get_call_info(void) const { - t_mutex_guard g(call_info.mutex); return call_info; } -- cgit v1.2.3