summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Mazieres <dm@uun.org>2017-12-28 23:49:10 -0800
committerDavid Mazieres <dm@uun.org>2017-12-28 23:49:10 -0800
commit252a934cad6a266e86074c96c9605b3f1f26cf36 (patch)
tree1e0fad1cc147f6f1579d3f663f87ed05b37fa34a
parenta7a89af780b7175a2e5dc60ba372715630beade0 (diff)
fix race conditionmuchsync-5
-rw-r--r--NEWS6
-rw-r--r--configure.ac2
-rw-r--r--infinibuf.cc1
-rw-r--r--infinibuf.h6
4 files changed, 12 insertions, 3 deletions
diff --git a/NEWS b/NEWS
index 1e5e9fe..3079eef 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+
+* Changes in release 5
+
+Fixed a race condition that could cause a core dump on fast networks
+when flow-control logic kicked in.
+
* Changes in release 4
Updated for GCC 7 header changes (thanks Toke Høiland-Jørgensen).
diff --git a/configure.ac b/configure.ac
index 0af6eaa..9533bff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
-AC_INIT(muchsync, 4)
+AC_INIT(muchsync, 5)
AM_INIT_AUTOMAKE([-Wall])
AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
diff --git a/infinibuf.cc b/infinibuf.cc
index b7640aa..e7ef5f8 100644
--- a/infinibuf.cc
+++ b/infinibuf.cc
@@ -178,6 +178,7 @@ infinibuf::input_loop(shared_ptr<infinibuf> ib, int fd)
else if (res == 0)
return;
// Don't even bother checking flow control if less than 1MB allocated
+ lock_guard<infinibuf> lk (*ib);
if (ib->buffer_size() >= 100000)
ib->pwait();
}
diff --git a/infinibuf.h b/infinibuf.h
index 1fd4788..2713ddf 100644
--- a/infinibuf.h
+++ b/infinibuf.h
@@ -184,9 +184,11 @@ public:
}
void pwait() override {
if (max_buf_size_ && buffer_size() > max_buf_size_) {
- std::unique_lock<std::mutex> ul (m_, std::adopt_lock);
- if (max_buf_size_ && buffer_size() > max_buf_size_)
+ if (max_buf_size_ && buffer_size() > max_buf_size_) {
+ std::unique_lock<std::mutex> ul (m_, std::adopt_lock);
flow_ctrl_cv_.wait(ul);
+ ul.release();
+ }
}
}
};