This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 0/1] Fix deadlocks related to child processes


For a long time I've been struggling with intermittent deadlocks and
segfaults in emacs, seemingly related to invoking child processes.  I
recently found a reliable way to reproduce one such deadlock:

- install clean cygwin with: emacs-w32, clang
- install flycheck from elpa
- grab some non trivial C header e.g.:
  $ cp /usr/include/stdio.h test.h
- $ emacs -q test.h
- start flycheck:
  (progn (package-initialize)
         (require 'flycheck)
         (flycheck-mode))
- add a character to the start of the first line
- wait for flygheck to complete
- repeat the last two steps until a deadlock occurs

Breaking in gdb showed the main thread in `cygheap_protect.acquire ()`,
from either _cfree or _cmalloc.  The thread holding the mutex was always
"flasio", and it would either be continually segfaulting or looping in
_cfree.

I added some debug prints to cygheap and determined that it flasio was
double-freeing an atomic_write_buf.  I added some more prints and found
that it was two different fhandler objects freeing the same buffer.

I then found that `fhandler_base_overlapped::copyto` would clear the
buffer pointer after the copy, but none of the derived classes (pipe,
fifo) did.

Attached is a patch which clears the buffer pointers when copying pipes
and fifos.

It would probably be safer to move the buffer clear to a `operator=`,
but I wanted to keep the patch as simple as possible and avoid
refactoring.


David McFarland (1):
  Cygwin: Fix cygheap corruption caused by cloned atomic buffer

 winsup/cygwin/fhandler.h | 2 ++
 1 file changed, 2 insertions(+)

-- 
2.19.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]