About file descriptor leaks

File descriptors represent handles to input and output streams available to a running program. They are small integer indices into a fixed table in the kernel's per-process data structure.

A common problem occurs when a file is opened within a program loop, or in response to user input, and is never closed. When no more file descriptors are available, programs usually fail, reporting a mysterious inability to open a file that they should be able to open.

Purify displays a File descriptors in use (FIU) message when your program exits, to help you discover such cases. Purify reports each open descriptor and where it was opened.

File descriptors in use messages

When a program starts, it can inherit file descriptors from a parent process. The origin of such inherited descriptors is invisible to Purify, and the message indicates only <inherited from parent>. Descriptors 0, 1, and 2 are often used in this manner to provide stdin, stdout, and stderr, respectively, for programs. If these descriptors are marked as inherited descriptors, the stdin, stdout, and stderr synonyms are attached.

If a file is open, Purify notes the file's name and mode in the message. If it is not a special file, Purify might also be able to determine the current file offset where the next byte would be read or written. The call chain shows where in the program the file was opened.

If a file descriptor is obtained from socketpair, pipe, or certain other system calls, Purify shows the call chain indicating the origin. No additional information is available.

If you duplicate a file descriptor from another file using the dup or dup2 system calls, Purify notes the call chain of the dup, but copies any other file information available from the source of the dup.

Purify prints a message for all file descriptors for which select or poll returns no error. Under some circumstances (for example, descriptors obtained by ioctls issued to non-standard device drivers), Purify might not be able to determine details about the origin of the file, and simply prints the text <unknown>.

Purify reserves file descriptors 26 and 27 for its own use. To change Purify's reserved file descriptors, use the -fds option.