diff options
author | David Zeuthen <davidz@redhat.com> | 2008-04-21 14:03:17 +0000 |
---|---|---|
committer | David Zeuthen <davidz@src.gnome.org> | 2008-04-21 14:03:17 +0000 |
commit | 0742e8b42c7a7e75f5c1caeae1e6aa2fc2bbf686 (patch) | |
tree | cb16419e78c9aad0878415477782502c789eaecd | |
parent | 03c4b14ee86127bdd7ed0c7057633d89a5be1c03 (diff) | |
download | gvfs-0742e8b42c7a7e75f5c1caeae1e6aa2fc2bbf686.tar.gz |
Fix some reference issues, see
2008-04-21 David Zeuthen <davidz@redhat.com>
* client/gvfsfusedaemon.c: Fix some reference issues, see
http://mail.gnome.org/archives/gvfs-list/2008-April/msg00017.html
svn path=/trunk/; revision=1749
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | client/gvfsfusedaemon.c | 37 |
2 files changed, 33 insertions, 9 deletions
@@ -1,3 +1,8 @@ +2008-04-21 David Zeuthen <davidz@redhat.com> + + * client/gvfsfusedaemon.c: Fix some reference issues, see + http://mail.gnome.org/archives/gvfs-list/2008-April/msg00017.html + 2008-04-20 David Zeuthen <davidz@redhat.com> * daemon/gvfsbackendarchive.c: some minor fixes (#528950) diff --git a/client/gvfsfusedaemon.c b/client/gvfsfusedaemon.c index 367b73dc..209f39aa 100644 --- a/client/gvfsfusedaemon.c +++ b/client/gvfsfusedaemon.c @@ -71,6 +71,8 @@ typedef enum { } FileOp; typedef struct { + gint refcount; + GMutex *mutex; FileOp op; gpointer stream; @@ -188,12 +190,26 @@ file_handle_new (void) FileHandle *file_handle; file_handle = g_new0 (FileHandle, 1); + file_handle->refcount = 1; file_handle->mutex = g_mutex_new (); file_handle->op = FILE_OP_NONE; return file_handle; } +static FileHandle * +file_handle_ref (FileHandle *file_handle) +{ + g_atomic_int_inc (&file_handle->refcount); + return file_handle; +} + +static gboolean +file_handle_unref (FileHandle *file_handle) +{ + return g_atomic_int_dec_and_test (&file_handle->refcount); +} + static void file_handle_close_stream (FileHandle *file_handle) { @@ -278,21 +294,19 @@ reindex_file_handle_for_path (const gchar *old_path, const gchar *new_path) g_static_mutex_unlock (&global_mutex); } -static gboolean +static void free_file_handle_for_path (const gchar *path) { FileHandle *fh; - fh = get_file_handle_for_path (path); + g_static_mutex_lock (&global_mutex); + fh = g_hash_table_lookup (global_fh_table, path); if (fh) { - g_static_mutex_lock (&global_mutex); - g_hash_table_remove (global_fh_table, path); - g_static_mutex_unlock (&global_mutex); - return TRUE; + if (file_handle_unref (fh)) + g_hash_table_remove (global_fh_table, path); } - - return FALSE; + g_static_mutex_unlock (&global_mutex); } static MountRecord * @@ -923,6 +937,7 @@ vfs_open (const gchar *path, struct fuse_file_info *fi) /* File exists */ + file_handle_ref (fh); SET_FILE_HANDLE (fi, fh); debug_print ("vfs_open: flags=%o\n", fi->flags); @@ -1013,6 +1028,7 @@ vfs_create (const gchar *path, mode_t mode, struct fuse_file_info *fi) /* Success */ + file_handle_ref (fh); SET_FILE_HANDLE (fi, fh); g_assert (fh->stream == NULL); @@ -1047,7 +1063,10 @@ vfs_release (const gchar *path, struct fuse_file_info *fi) debug_print ("vfs_release: %s\n", path); if (fh) - free_file_handle_for_path (path); + { + if (!file_handle_unref (fh)) + free_file_handle_for_path (path); + } return 0; } |