server: Avoid leaking file descriptor on error in create_file_for_fd.

This commit is contained in:
Sebastian Lackner 2014-11-17 19:19:08 +01:00 committed by Alexandre Julliard
parent 609d43e408
commit 3d3c92782a
1 changed files with 14 additions and 10 deletions

View File

@ -120,11 +120,16 @@ struct file *create_file_for_fd( int fd, unsigned int access, unsigned int shari
if (fstat( fd, &st ) == -1)
{
file_set_error();
close( fd );
return NULL;
}
if ((file = alloc_object( &file_ops )))
if (!(file = alloc_object( &file_ops )))
{
close( fd );
return NULL;
}
file->mode = st.st_mode;
file->access = default_fd_map_access( &file->obj, access );
if (!(file->fd = create_anonymous_fd( &file_fd_ops, fd, &file->obj,
@ -134,7 +139,6 @@ struct file *create_file_for_fd( int fd, unsigned int access, unsigned int shari
return NULL;
}
allow_fd_caching( file->fd );
}
return file;
}