file_descriptor::ops is now set to NULL when the file descriptor gets disconnected.
This fixes a possible crashing bug when an application with disconnected descriptors quits. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19951 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
c91c8f1d32
commit
d2dec0aafa
@ -1,6 +1,6 @@
|
||||
/* Operations on file descriptors
|
||||
*
|
||||
* Copyright 2002-2006, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@ -134,12 +134,13 @@ put_fd(struct file_descriptor *descriptor)
|
||||
// free the descriptor if we don't need it anymore
|
||||
if (previous == 1) {
|
||||
// free the underlying object
|
||||
if (descriptor->ops->fd_free)
|
||||
if (descriptor->ops != NULL && descriptor->ops->fd_free != NULL)
|
||||
descriptor->ops->fd_free(descriptor);
|
||||
|
||||
free(descriptor);
|
||||
} else if ((descriptor->open_mode & O_DISCONNECTED) != 0
|
||||
&& previous - 1 == descriptor->open_count) {
|
||||
&& previous - 1 == descriptor->open_count
|
||||
&& descriptor->ops != NULL) {
|
||||
// the descriptor has been disconnected - it cannot
|
||||
// be accessed anymore, let's close it (no one is
|
||||
// currently accessing this descriptor)
|
||||
@ -152,6 +153,7 @@ put_fd(struct file_descriptor *descriptor)
|
||||
// prevent this descriptor from being closed/freed again
|
||||
descriptor->open_count = -1;
|
||||
descriptor->ref_count = -1;
|
||||
descriptor->ops = NULL;
|
||||
descriptor->u.vnode = NULL;
|
||||
|
||||
// the file descriptor is kept intact, so that it's not
|
||||
@ -170,7 +172,7 @@ close_fd(struct file_descriptor *descriptor)
|
||||
if (atomic_add(&descriptor->open_count, -1) == 1) {
|
||||
vfs_unlock_vnode_if_locked(descriptor);
|
||||
|
||||
if (descriptor->ops->fd_close)
|
||||
if (descriptor->ops != NULL && descriptor->ops->fd_close != NULL)
|
||||
descriptor->ops->fd_close(descriptor);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user