Commit in reactos/subsys/win32k on MAIN
include/hook.h+31.2 -> 1.3
ntuser/hook.c+27-41.6 -> 1.7
+30-4
2 modified files
fixed missing dereferences of threads

reactos/subsys/win32k/include
hook.h 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- hook.h	24 Feb 2004 13:27:02 -0000	1.2
+++ hook.h	7 Apr 2004 00:58:05 -0000	1.3
@@ -4,6 +4,8 @@
 #include <windows.h>
 #include <internal/ps.h>
 
+#define HOOK_THREAD_REFERENCED	(0x1)
+
 typedef struct tagHOOK
 {
   LIST_ENTRY Chain;          /* Hook chain entry */
@@ -12,6 +14,7 @@
   int        HookId;         /* Hook table index */
   HOOKPROC   Proc;           /* Hook function */
   BOOLEAN    Ansi;           /* Is it an Ansi hook? */
+  ULONG      Flags;          /* Some internal flags */
   UNICODE_STRING ModuleName; /* Module name for global hooks */
 } HOOK, *PHOOK;
 

reactos/subsys/win32k/ntuser
hook.c 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- hook.c	24 Feb 2004 13:27:03 -0000	1.6
+++ hook.c	7 Apr 2004 00:58:05 -0000	1.7
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: hook.c,v 1.6 2004/02/24 13:27:03 weiden Exp $
+/* $Id: hook.c,v 1.7 2004/04/07 00:58:05 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -190,7 +190,12 @@
 {
   RemoveEntryList(&Hook->Chain);
   RtlFreeUnicodeString(&Hook->ModuleName);
-
+  
+  /* Dereference thread if required */
+  if(Hook->Flags & HOOK_THREAD_REFERENCED)
+    ObDereferenceObject(Hook->Thread);
+  
+  /* Close handle */
   ObmCloseHandle(WinStaObj->HandleTable, Hook->Self);
 }
 
@@ -438,7 +443,7 @@
   BOOL Ansi)
 {
   PWINSTATION_OBJECT WinStaObj;
-  BOOLEAN Global;
+  BOOLEAN Global, ReleaseThread;
   PETHREAD Thread;
   PHOOK Hook;
   UNICODE_STRING ModuleName;
@@ -473,13 +478,16 @@
         }
       if (Thread->ThreadsProcess != PsGetCurrentProcess())
         {
+          ObDereferenceObject(Thread);
           DPRINT1("Can't specify thread belonging to another process\n");
           SetLastWin32Error(ERROR_INVALID_PARAMETER);
           return NULL;
         }
+      ReleaseThread = TRUE;
     }
   else  /* system-global hook */
     {
+      ReleaseThread = FALSE;
       if (HookId == WH_KEYBOARD_LL || HookId == WH_MOUSE_LL)
         {
           Mod = NULL;
@@ -505,6 +513,8 @@
 #else
       DPRINT1("Not implemented: HookId %d Global %s\n", HookId, Global ? "TRUE" : "FALSE");
 #endif
+      if(ReleaseThread)
+        ObDereferenceObject(Thread);
       SetLastWin32Error(ERROR_NOT_SUPPORTED);
       return NULL;
     }
@@ -516,6 +526,8 @@
   
   if(! NT_SUCCESS(Status))
     {
+      if(ReleaseThread && Thread)
+        ObDereferenceObject(Thread);
       SetLastNtError(Status);
       return (HANDLE) NULL;
     }
@@ -523,10 +535,15 @@
   Hook = IntAddHook(Thread, HookId, Global, WinStaObj);
   if (NULL == Hook)
     {
+      if(ReleaseThread)
+        ObDereferenceObject(Thread);
       ObDereferenceObject(WinStaObj);
       return NULL;
     }
-
+  
+  if(ReleaseThread)
+    Hook->Flags |= HOOK_THREAD_REFERENCED;
+  
   if (NULL != Mod)
     {
       Status = MmCopyFromCaller(&ModuleName, UnsafeModuleName, sizeof(UNICODE_STRING));
@@ -534,6 +551,8 @@
         {
           ObmDereferenceObject(Hook);
           IntRemoveHook(Hook, WinStaObj);
+          if(ReleaseThread)
+            ObDereferenceObject(Thread);
           ObDereferenceObject(WinStaObj);
           SetLastNtError(Status);
           return NULL;
@@ -545,6 +564,8 @@
         {
           ObmDereferenceObject(Hook);
           IntRemoveHook(Hook, WinStaObj);
+          if(ReleaseThread)
+            ObDereferenceObject(Thread);
           ObDereferenceObject(WinStaObj);
           SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
           return NULL;
@@ -557,6 +578,8 @@
         {
           ObmDereferenceObject(Hook);
           IntRemoveHook(Hook, WinStaObj);
+          if(ReleaseThread)
+            ObDereferenceObject(Thread);
           ObDereferenceObject(WinStaObj);
           SetLastNtError(Status);
           return NULL;
CVSspam 0.2.8