Browse code

Merge pull request #31263 from nalind/journal-doublefree

Synchronize the cursor returned by followJournal

Alexander Morozov authored on 2017/02/23 10:45:49
Showing 1 changed files
... ...
@@ -249,6 +249,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
249 249
 	s.readers.readers[logWatcher] = logWatcher
250 250
 	s.readers.mu.Unlock()
251 251
 
252
+	newCursor := make(chan *C.char)
253
+
252 254
 	go func() {
253 255
 		for {
254 256
 			// Keep copying journal data out until we're notified to stop
... ...
@@ -276,6 +278,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
276 276
 		delete(s.readers.readers, logWatcher)
277 277
 		s.readers.mu.Unlock()
278 278
 		close(logWatcher.Msg)
279
+		newCursor <- cursor
279 280
 	}()
280 281
 
281 282
 	// Wait until we're told to stop.
... ...
@@ -285,6 +288,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
285 285
 		C.close(pfd[1])
286 286
 	}
287 287
 
288
+	cursor = <-newCursor
289
+
288 290
 	return cursor
289 291
 }
290 292