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:
@@ -1,6 +1,6 @@
|
|||||||
/* Operations on file descriptors
|
/* Operations on file descriptors
|
||||||
*
|
*
|
||||||
* Copyright 2002-2006, Axel Dörfler, [email protected].
|
* Copyright 2002-2007, Axel Dörfler, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* 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
|
// free the descriptor if we don't need it anymore
|
||||||
if (previous == 1) {
|
if (previous == 1) {
|
||||||
// free the underlying object
|
// free the underlying object
|
||||||
if (descriptor->ops->fd_free)
|
if (descriptor->ops != NULL && descriptor->ops->fd_free != NULL)
|
||||||
descriptor->ops->fd_free(descriptor);
|
descriptor->ops->fd_free(descriptor);
|
||||||
|
|
||||||
free(descriptor);
|
free(descriptor);
|
||||||
} else if ((descriptor->open_mode & O_DISCONNECTED) != 0
|
} 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
|
// the descriptor has been disconnected - it cannot
|
||||||
// be accessed anymore, let's close it (no one is
|
// be accessed anymore, let's close it (no one is
|
||||||
// currently accessing this descriptor)
|
// currently accessing this descriptor)
|
||||||
@@ -152,6 +153,7 @@ put_fd(struct file_descriptor *descriptor)
|
|||||||
// prevent this descriptor from being closed/freed again
|
// prevent this descriptor from being closed/freed again
|
||||||
descriptor->open_count = -1;
|
descriptor->open_count = -1;
|
||||||
descriptor->ref_count = -1;
|
descriptor->ref_count = -1;
|
||||||
|
descriptor->ops = NULL;
|
||||||
descriptor->u.vnode = NULL;
|
descriptor->u.vnode = NULL;
|
||||||
|
|
||||||
// the file descriptor is kept intact, so that it's not
|
// 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) {
|
if (atomic_add(&descriptor->open_count, -1) == 1) {
|
||||||
vfs_unlock_vnode_if_locked(descriptor);
|
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);
|
descriptor->ops->fd_close(descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user