ntdll: Assert when trying to replace an exiting file descriptor in fd_cache.

Sebastian Lackner sebastian at fds-team.de
Wed Mar 4 01:34:07 CST 2015

On 04.03.2015 08:15, Alexandre Julliard wrote:
> Sebastian Lackner <sebastian at fds-team.de> writes:
>> The condition "prev_fd != -1" should never be true. If this is the case then something
>> is going terrible wrong, and it is better to assert instead of just closing the file
>> descriptor.
> It can happen if the handle was closed on the server side but not yet
> removed from the cache. Yes, handling of that case is not ideal, but an
> assert is not an improvement.

Thanks for taking a look. Hm, from which codepath can it happen that prev_fd != -1?
The function add_fd_to_cache is only called from server_get_unix_fd, and immediately
before that there is a call to get_cached_fd. If an fd is cached, then the whole code
will never be executed (even if its probably the wrong cached file descriptor).

Since its all in an uninterrupted section I also see no other reason why fd_cache
should change between get_cached_fd and add_fd_to_cache. Could you explain this a bit?
server_remove_fd_from_cache shouldn't cause any harm, because this function can only
unset a fd_cache entry.

More information about the wine-devel mailing list