Alexandre Julliard : server: Don't set last error in close_handle(), return the error code instead.

Alexandre Julliard julliard at winehq.org
Tue Dec 1 09:19:43 CST 2009


Module: wine
Branch: master
Commit: 60efdd55eaf73bf556dc9ab97745780f911da3f0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=60efdd55eaf73bf556dc9ab97745780f911da3f0

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec  1 13:59:41 2009 +0100

server: Don't set last error in close_handle(), return the error code instead.

---

 server/handle.c     |   33 ++++++++-------------------------
 server/handle.h     |    2 +-
 server/winstation.c |    5 ++---
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/server/handle.c b/server/handle.c
index d1b6a14..3baaa6d 100644
--- a/server/handle.c
+++ b/server/handle.c
@@ -347,35 +347,22 @@ struct handle_table *copy_handle_table( struct process *process, struct process
 }
 
 /* close a handle and decrement the refcount of the associated object */
-/* return 1 if OK, 0 on error */
-int close_handle( struct process *process, obj_handle_t handle )
+unsigned int close_handle( struct process *process, obj_handle_t handle )
 {
     struct handle_table *table;
     struct handle_entry *entry;
     struct object *obj;
 
-    if (!(entry = get_handle( process, handle )))
-    {
-        set_error( STATUS_INVALID_HANDLE );
-        return 0;
-    }
-    if (entry->access & RESERVED_CLOSE_PROTECT)
-    {
-        set_error( STATUS_HANDLE_NOT_CLOSABLE );
-        return 0;
-    }
+    if (!(entry = get_handle( process, handle ))) return STATUS_INVALID_HANDLE;
+    if (entry->access & RESERVED_CLOSE_PROTECT) return STATUS_HANDLE_NOT_CLOSABLE;
     obj = entry->ptr;
-    if (!obj->ops->close_handle( obj, process, handle ))
-    {
-        set_error( STATUS_HANDLE_NOT_CLOSABLE );
-        return 0;
-    }
+    if (!obj->ops->close_handle( obj, process, handle )) return STATUS_HANDLE_NOT_CLOSABLE;
     entry->ptr = NULL;
     table = handle_is_global(handle) ? global_table : process->handles;
     if (entry < table->entries + table->free) table->free = entry - table->entries;
     if (entry == table->entries + table->last) shrink_handle_table( table );
     release_object( obj );
-    return 1;
+    return STATUS_SUCCESS;
 }
 
 /* retrieve the object corresponding to one of the magic pseudo-handles */
@@ -567,7 +554,8 @@ unsigned int get_handle_table_count( struct process *process )
 /* close a handle */
 DECL_HANDLER(close_handle)
 {
-    close_handle( current->process, req->handle );
+    unsigned int err = close_handle( current->process, req->handle );
+    set_error( err );
 }
 
 /* set a handle information */
@@ -596,12 +584,7 @@ DECL_HANDLER(dup_handle)
             release_object( dst );
         }
         /* close the handle no matter what happened */
-        if (req->options & DUP_HANDLE_CLOSE_SOURCE)
-        {
-            unsigned int err = get_error();  /* don't overwrite error from the above calls */
-            reply->closed = close_handle( src, req->src_handle );
-            set_error( err );
-        }
+        if (req->options & DUP_HANDLE_CLOSE_SOURCE) reply->closed = !close_handle( src, req->src_handle );
         reply->self = (src == current->process);
         release_object( src );
     }
diff --git a/server/handle.h b/server/handle.h
index 3809aa3..7860f52 100644
--- a/server/handle.h
+++ b/server/handle.h
@@ -38,7 +38,7 @@ extern obj_handle_t alloc_handle( struct process *process, void *obj,
                                   unsigned int access, unsigned int attr );
 extern obj_handle_t alloc_handle_no_access_check( struct process *process, void *ptr,
                                                   unsigned int access, unsigned int attr );
-extern int close_handle( struct process *process, obj_handle_t handle );
+extern unsigned int close_handle( struct process *process, obj_handle_t handle );
 extern struct object *get_handle_obj( struct process *process, obj_handle_t handle,
                                       unsigned int access, const struct object_ops *ops );
 extern unsigned int get_handle_access( struct process *process, obj_handle_t handle );
diff --git a/server/winstation.c b/server/winstation.c
index cfff0a4..7ddc277 100644
--- a/server/winstation.c
+++ b/server/winstation.c
@@ -403,7 +403,6 @@ void close_thread_desktop( struct thread *thread )
 
     thread->desktop = 0;
     if (handle) close_handle( thread->process, handle );
-    clear_error();  /* ignore errors */
 }
 
 /* set the reply data from the object name */
@@ -458,7 +457,7 @@ DECL_HANDLER(close_winstation)
     if ((winstation = (struct winstation *)get_handle_obj( current->process, req->handle,
                                                            0, &winstation_ops )))
     {
-        if (!close_handle( current->process, req->handle )) set_error( STATUS_ACCESS_DENIED );
+        if (close_handle( current->process, req->handle )) set_error( STATUS_ACCESS_DENIED );
         release_object( winstation );
     }
 }
@@ -544,7 +543,7 @@ DECL_HANDLER(close_desktop)
     if ((desktop = (struct desktop *)get_handle_obj( current->process, req->handle,
                                                      0, &desktop_ops )))
     {
-        if (!close_handle( current->process, req->handle )) set_error( STATUS_DEVICE_BUSY );
+        if (close_handle( current->process, req->handle )) set_error( STATUS_DEVICE_BUSY );
         release_object( desktop );
     }
 }




More information about the wine-cvs mailing list