Hi,

We have been seeing a crash on windows when connecting to an android target using lldb-server.
I am not sure if this affects other platforms too.
I think this was introduced with http://reviews.llvm.org/D9056.

I tracked the crash back to the workings of ModuleCache::GetAndPut().

The crash seems to be due to a file descriptor being released twice, once by the original "File lock_file" and again by the "LockFile lock" who share the same file descriptor.

The file descriptor sharing happens because of this line:
ModuleCache.cpp @ 164
LockFile lock (lock_file.GetDescriptor ());

Both destructors attempt to release effectively the same file descriptor. I was able to fix the crash by duplicating the file handle in the lock file constructor using _dup(). (patch attached)
I wasn't sure if this was the right fix however. Has anyone else seen this?
Should "File lock_file" perhaps transfer its file descriptor completely rather then share it?

Thanks,
Aidan
diff --git a/source/Host/windows/LockFileWindows.cpp b/source/Host/windows/LockFileWindows.cpp
index 978821e..ce491b4 100644
--- a/source/Host/windows/LockFileWindows.cpp
+++ b/source/Host/windows/LockFileWindows.cpp
@@ -38,7 +38,7 @@ Error fileLock (HANDLE file_handle, DWORD flags, const uint64_t start, const uin
 
 LockFileWindows::LockFileWindows (int fd)
     : LockFileBase (fd),
-      m_file (reinterpret_cast<HANDLE> (_get_osfhandle (fd)))
+      m_file (reinterpret_cast<HANDLE> (_get_osfhandle (_dup(fd))))
 {
 }
 
_______________________________________________
lldb-dev mailing list
lldb-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev

Reply via email to