[SSSD] [PATCH] LDAP: Fix leak of file descriptors

Jakub Hrozek jhrozek at redhat.com
Wed Nov 4 19:39:46 UTC 2015


On Wed, Nov 04, 2015 at 03:22:20PM +0100, Lukas Slebodnik wrote:
> >Do you think it would be safer to initialize state->sd to -1 after the
> >state is created and only close state->sd if it's > 1? I think if the
> >socket() call would fail, then state->sd was 0 (because tevent uses
> >talloc_zero to create the state) and then we might attempt to close
> >stdin..
> The state->sd would be initialized either by socket or in
> part if HAVE_LDAP_INIT_FD is not defined to -1.
> 
> It could be 0 only in case if function socket returned 0.
> which is very unlikely. The file descriptor 0 would be already
> occupied by other file. But we shoudl not rely on this.
> 
> and on the other hand it's nicer to test for -1.

Thanks. I still think it would be better to initialize the socket FD to
-1 after the state is created.

But if you feel too strongly, I won't oppose. I just think if the code
was confusing to me now it might be confusing for other developers
trying to find bugs in the future...


More information about the sssd-devel mailing list