I participate in various C ++ projects (mainly using MSVC6 to MSVC10), in which we recently discovered several handle leaks (thread handles set by CreateThread ). I suspect there are many other pens that also leak out, and I would like to integrate a test that checks that no pens fall into our nightly test results.
My idea was to develop a DLL that equips the corresponding kernel32.dll functions (CreateThread, OpenProcess, CreateProcess and a dozen more), as well as CloseHandle . Then, the DLL for each descriptor being processed remembers the return line. At the end of the process, the DLL printed all the traces of the descriptors that were not closed to any log file, which can then be analyzed using a test environment.
This, of course, will also give backtraces for all descriptors that are still available (so they didn’t leak technically - perhaps the author assumed that the OS restores them when the process ends), but I think that closing them is clearly not because that we already have some good RAII shells for this material, we just don't use it as much as we should.
Now I wonder - this seems like a pretty simple approach; maybe someone here maybe identifies a library that is already doing this?
source share