[A fix related to closing C++ header file descriptors on windows]

Manuel Klimek via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 27 04:54:23 PDT 2016


Stumbling over this (much too late, of course), is this still a problem for
you?

On Thu, Nov 26, 2015 at 5:01 PM jean-yves desbree via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> I use clang 3.6.2 with qt creator 3.5.1 on windows 7 for parsing code in
> this IDE.
> It works well.
>
> However, I can see that clang keeps a few times some file descriptors
> opened on c++ header files (h files) after having parsed a cpp file (that
> includes these h files).
> The effect is that we cannot save these h files, what is quite frustrating
> when using an IDE.
>
> After debugging clang, I remarked that there was a file descriptor leak in
> the method Preprocessor::HandleIncludeDirective
> (file tools/clang/lib/Lex/PPDirectives.cpp)
>
> The object 'FileEntry *File' is created (for a given h file) and after
> some checks, the regular treatment calls EnterSourceFile.
> The File object is detroyed during this call (quite deeply in the stack)
>
> However, when some errors occur, the execution path goes through early
> returns and other code pathes.
> In this case, the file descriptor associated to File is not closed and the
> file descriptor remains open.
>
> So I did a correction that uses RAII in order to have the file descriptor
> closed.
> So I wrapped 'FileEntry *File' in a dedicated 'FileEntryCloser
> fileEntryCloser(File)'
>
> On regular treatment, the closer is released:
>   // If all is good, enter the new file!
>   if (EnterSourceFile(FID, CurDir, FilenameTok.getLocation()))
>   {
>      fileEntryCloser.release();
>      return;
>   }
>
> Otherwise, the file descriptor is closed
>    ~FileEntryCloser()
>    {
>       if(m_File)
>          m_File->closeFile();
>    }
>
>
> Now, I have no more remaining file descriptors ...
> Would it be possible to have an evaluation on that?
>
> Thanks in advance.
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160427/52aa505b/attachment-0001.html>


More information about the cfe-commits mailing list