diff --git a/server/handle.c b/server/handle.c
index 9d91f16c8146c52fe0ee5c6362c969cbaff6799b..c7cd41729c57b9d8b8161e48f72e93b2f9491823 100644
--- a/server/handle.c
+++ b/server/handle.c
@@ -403,14 +403,19 @@ struct object *get_handle_obj( struct process *process, obj_handle_t handle,
             set_error( STATUS_INVALID_HANDLE );
             return NULL;
         }
+        obj = entry->ptr;
+        if (ops && (obj->ops != ops))
+        {
+            set_error( STATUS_OBJECT_TYPE_MISMATCH );  /* not the right type */
+            return NULL;
+        }
         if ((entry->access & access) != access)
         {
             set_error( STATUS_ACCESS_DENIED );
             return NULL;
         }
-        obj = entry->ptr;
     }
-    if (ops && (obj->ops != ops))
+    else if (ops && (obj->ops != ops))
     {
         set_error( STATUS_OBJECT_TYPE_MISMATCH );  /* not the right type */
         return NULL;