Browse Source

fix race condition

David Mazieres 3 years ago
parent
commit
252a934cad
4 changed files with 12 additions and 3 deletions
  1. 6
    0
      NEWS
  2. 1
    1
      configure.ac
  3. 1
    0
      infinibuf.cc
  4. 4
    2
      infinibuf.h

+ 6
- 0
NEWS View File

@@ -1,3 +1,9 @@
1
+
2
+* Changes in release 5
3
+
4
+Fixed a race condition that could cause a core dump on fast networks
5
+when flow-control logic kicked in.
6
+
1 7
 * Changes in release 4
2 8
 
3 9
 Updated for GCC 7 header changes (thanks Toke Høiland-Jørgensen).

+ 1
- 1
configure.ac View File

@@ -2,7 +2,7 @@
2 2
 # Process this file with autoconf to produce a configure script.
3 3
 
4 4
 AC_PREREQ([2.69])
5
-AC_INIT(muchsync, 4)
5
+AC_INIT(muchsync, 5)
6 6
 AM_INIT_AUTOMAKE([-Wall])
7 7
 AC_CONFIG_SRCDIR([configure.ac])
8 8
 AC_CONFIG_MACRO_DIR([m4])

+ 1
- 0
infinibuf.cc View File

@@ -178,6 +178,7 @@ infinibuf::input_loop(shared_ptr<infinibuf> ib, int fd)
178 178
       else if (res == 0)
179 179
 	return;
180 180
       // Don't even bother checking flow control if less than 1MB allocated
181
+      lock_guard<infinibuf> lk (*ib);
181 182
       if (ib->buffer_size() >= 100000)
182 183
 	ib->pwait();
183 184
     }

+ 4
- 2
infinibuf.h View File

@@ -184,9 +184,11 @@ public:
184 184
   }
185 185
   void pwait() override {
186 186
     if (max_buf_size_ && buffer_size() > max_buf_size_) {
187
-      std::unique_lock<std::mutex> ul (m_, std::adopt_lock);
188
-      if (max_buf_size_ && buffer_size() > max_buf_size_)
187
+      if (max_buf_size_ && buffer_size() > max_buf_size_) {
188
+	std::unique_lock<std::mutex> ul (m_, std::adopt_lock);
189 189
 	flow_ctrl_cv_.wait(ul);
190
+	ul.release();
191
+      }
190 192
     }
191 193
   }
192 194
 };

Loading…
Cancel
Save