Process's file descriptor table slot is being leaked

Number:rdar://36148377 Date Originated:12/20/2017
Status:open Resolved:No
Product:Mac OSX Product Version:10.13
Classification:1 Reproducible:
Process' file descriptor table slot is being leaked.

First Reported here -

Steps to Reproduce:
message "Too many open files in system" converted to "Too many open files" got me curious and I believe this is bug. It led me to -

function falloc_withalloc_locked()
static int
falloc_withalloc_locked(proc_t p, struct fileproc **resultfp, int *resultfd,
	vfs_context_t ctx, fp_allocfn_t fp_zalloc, void *crarg,
	int locked) 
	if ( (error = fdalloc(p, 0, &nfd)) ) {
		if (!locked)
		return (error);

	if (nfiles >= maxfiles) {
		if (!locked)
		return (ENFILE);

Change of message from "Too many open files in system" to "Too many open files" is manifestation of a bug in the form of resource leak ( process's file descriptor table slot is being leaked here) -
Call to fdalloc(p, 0, &nfd) checks that if the process is opening more than the number of files it can open and reserve a slot in the file-descriptor table which is returned via nfd.

If "(nfiles >= maxfiles) " fails then is not un-reserving that slot. That way here is the resource leak.
If these two if conditions are swapped then it solves this problem.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!