protected EmuUnixFileDescriptor<T> releaseFd(int fd) {
		synchronized (descriptors) {
			if (descriptors.size() + closedFds.size() - 1 == fd) {
				return descriptors.remove(fd);
			}
			EmuUnixFileDescriptor<T> removed = descriptors.remove(fd);
			if (removed == null) {
				throw new EmuUnixException("Invalid descriptor: " + fd, getErrno(Errno.EBADF));
			}
			closedFds.add(fd);
			return removed;
		}
	}
Release/invalidate the given file descriptor number

@param fd the file descriptor number
@return the removed descriptor object
@throws EmuUnixException with {@link Errno#EBADF} if the file descriptor is invalid
Ghidra/Features/SystemEmulation/src/main/java/ghidra/pcode/emu/unix/AbstractEmuUnixSyscallUseropLibrary.java