What can cause leakage of section handles?

This is the next question to my previous question.

As suggested in this answer to my previous question , I used ProcessExplorer to analyze the list of handles that my application uses to find a handle leak.

Leaks that leak are of type Section .

What is a section descriptor, where is it used, and what can cause section descriptors to leak?

I do not use memory mapped files in my code.

+8
windows delphi delphi-xe handle
source share
4 answers

Quote from Mark Russinovich In Windows 2000 (what is now called internal) Windows,

The partition object that the Win32 subsystem calls the file association object is a memory block that two or more processes can share.

So this is a memory mapped file. They will flow if you created a file with memory mapping and could not close it. It is rather difficult to be more specific.

+4
source share

It turns out the problem was in a low-level function that counts the number of threads in the current process. This function used

CreateToolhelp32Snapshot 

An API function that returns a handle that has not been closed properly. I'm not sure why this leads to a section handle leak.

+3
source share

A memory mapped file that is not associated with a file descriptor can be used for IPC (process communication). If you are not using them directly, it is possible that one of your device or component is performing some communication with IPC. It is very likely that you are using a component to connect to another process and are not freeing it upon request.

The first action you need to take is to monitor for a memory leak (using FastMM4 debugging mode), and you will definitely find some non-running objects in your code.

Since handles are usually allocated by objects, from my experiment, troubleshooting memory leaks eliminates handle leaks.

If you don't have a memory leak, there are several CreateFileMapping() to check the corresponding CloseHandle() in all of your code sources (including a third-party source).

+2
source share

The section descriptor error in .net is related to Microsoft Hotfix KB2670838. Uninstall this update and the issue of the Out of Memory section handle leak will be fixed.

 Parameter is not valid. at System.Drawing.Image.get_Width() at System.Drawing.Image.get_Size() 
+1
source share

All Articles