Change ExFreePool to ExFreePoolWithTag
Don't call RtlFreeUnicodeString if the string wasn't created by RtlAnsiStringToUnicodeString or RtlUpcaseUnicodeString
Implement ExRosQueryNonPagedPoolTag
Add BAD_POOL_CALLER code
Modified: trunk/reactos/ntoskrnl/cm/regobj.c
Modified: trunk/reactos/ntoskrnl/io/device.c
Modified: trunk/reactos/ntoskrnl/io/irp.c
Modified: trunk/reactos/ntoskrnl/io/mdl.c
Modified: trunk/reactos/ntoskrnl/mm/marea.c
Modified: trunk/reactos/ntoskrnl/mm/mdl.c
Modified: trunk/reactos/ntoskrnl/mm/npool.c
Modified: trunk/reactos/ntoskrnl/ntoskrnl.mc
Modified: trunk/reactos/ntoskrnl/ob/object.c

Modified: trunk/reactos/ntoskrnl/cm/regobj.c
--- trunk/reactos/ntoskrnl/cm/regobj.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/cm/regobj.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -91,7 +91,7 @@
   {
      ExReleaseResourceLite(&CmiRegistryLock);
      KeLeaveCriticalRegion();
-     RtlFreeUnicodeString(&KeyName);
+     ExFreePool(KeyName.Buffer);
      return Status;
   }
   if (FoundObject == NULL)
@@ -107,7 +107,7 @@
 	{
           ExReleaseResourceLite(&CmiRegistryLock);
           KeLeaveCriticalRegion();
-	  RtlFreeUnicodeString(&KeyName);
+	  ExFreePool(KeyName.Buffer);
 	  return(STATUS_UNSUCCESSFUL);
 	}
 
@@ -140,7 +140,7 @@
 		  wcscat(TargetPath.Buffer, EndPtr);
 		}
 
-	      RtlFreeUnicodeString(FullPath);
+	      ExFreePool(FullPath->Buffer);
 	      RtlFreeUnicodeString(&LinkPath);
 	      FullPath->Length = TargetPath.Length;
 	      FullPath->MaximumLength = TargetPath.MaximumLength;
@@ -153,7 +153,7 @@
 
 	      *NextObject = NULL;
 
-	      RtlFreeUnicodeString(&KeyName);
+	      ExFreePool(KeyName.Buffer);
 	      return(STATUS_REPARSE);
 	    }
 	}
@@ -173,7 +173,7 @@
 	{
           ExReleaseResourceLite(&CmiRegistryLock);
           KeLeaveCriticalRegion();
-	  RtlFreeUnicodeString(&KeyName);
+	  ExFreePool(KeyName.Buffer);
 	  return(Status);
 	}
       /* Add the keep-alive reference */
@@ -224,8 +224,8 @@
 		  wcscat(TargetPath.Buffer, EndPtr);
 		}
 
-	      RtlFreeUnicodeString(FullPath);
-	      RtlFreeUnicodeString(&LinkPath);
+	      ExFreePool(FullPath->Buffer);
+	      ExFreePool(LinkPath.Buffer);
 	      FullPath->Length = TargetPath.Length;
 	      FullPath->MaximumLength = TargetPath.MaximumLength;
 	      FullPath->Buffer = TargetPath.Buffer;
@@ -237,7 +237,7 @@
 
 	      *NextObject = NULL;
 
-	      RtlFreeUnicodeString(&KeyName);
+	      ExFreePool(KeyName.Buffer);
 	      return(STATUS_REPARSE);
 	    }
 	}
@@ -258,7 +258,7 @@
 
   *NextObject = FoundObject;
 
-  RtlFreeUnicodeString(&KeyName);
+  ExFreePool(KeyName.Buffer);
 
   return(STATUS_SUCCESS);
 }

Modified: trunk/reactos/ntoskrnl/io/device.c
--- trunk/reactos/ntoskrnl/io/device.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/io/device.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -18,6 +18,7 @@
 
 #define TAG_DEVICE_EXTENSION   TAG('D', 'E', 'X', 'T')
 #define TAG_SHUTDOWN_ENTRY    TAG('S', 'H', 'U', 'T')
+#define TAG_IO_TIMER      TAG('I', 'O', 'T', 'M')
 
 static ULONG IopDeviceObjectNumber = 0;
 
@@ -589,7 +590,7 @@
    if (DeviceObject->Timer)
    {
       IopRemoveTimerFromTimerList(DeviceObject->Timer);
-      ExFreePool(DeviceObject->Timer);
+      ExFreePoolWithTag(DeviceObject->Timer, TAG_IO_TIMER);
    }
 
    /* Remove device from driver device list */

Modified: trunk/reactos/ntoskrnl/io/irp.c
--- trunk/reactos/ntoskrnl/io/irp.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/io/irp.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -871,7 +871,7 @@
 IoFreeIrp(PIRP Irp)
 {
     /* Free the pool memory associated with it */
-    ExFreePool(Irp);
+    ExFreePoolWithTag(Irp, TAG_IRP);
 }
 
 /*
@@ -1253,7 +1253,7 @@
         /* Also check if we should de-allocate it */
         if (Irp->Flags & IRP_DEALLOCATE_BUFFER)
         {
-            ExFreePool(Irp->AssociatedIrp.SystemBuffer);
+            ExFreePoolWithTag(Irp->AssociatedIrp.SystemBuffer, TAG_SYS_BUF);
         }
     }
     

Modified: trunk/reactos/ntoskrnl/io/mdl.c
--- trunk/reactos/ntoskrnl/io/mdl.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/io/mdl.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -132,7 +132,7 @@
 
    MmPrepareMdlForReuse(Mdl);
 
-   ExFreePool(Mdl);
+   ExFreePoolWithTag(Mdl, TAG_MDL);
 }
 
 

Modified: trunk/reactos/ntoskrnl/mm/marea.c
--- trunk/reactos/ntoskrnl/mm/marea.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/mm/marea.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -812,7 +812,7 @@
       }
    }
 
-   ExFreePool(MemoryArea);
+   ExFreePoolWithTag(MemoryArea, TAG_MAREA);
 
    DPRINT("MmFreeMemoryAreaByNode() succeeded\n");
 

Modified: trunk/reactos/ntoskrnl/mm/mdl.c
--- trunk/reactos/ntoskrnl/mm/mdl.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/mm/mdl.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -16,7 +16,7 @@
 
 /* GLOBALS *******************************************************************/
 
-#define TAG_MDL    TAG('M', 'M', 'D', 'L')
+#define TAG_MDL    TAG('M', 'D', 'L', ' ')
 
 #define MI_MDL_MAPPING_REGION_SIZE       (256*1024*1024)
 

Modified: trunk/reactos/ntoskrnl/mm/npool.c
--- trunk/reactos/ntoskrnl/mm/npool.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/mm/npool.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -1458,6 +1458,28 @@
 
 #endif /* not WHOLE_PAGE_ALLOCATIONS */
 
+ULONG STDCALL
+ExRosQueryNonPagedPoolTag ( PVOID Addr )
+{
+#ifdef WHOLE_PAGE_ALLOCATIONS /* WHOLE_PAGE_ALLOCATIONS */
+
+   UNIMPLEMENTED;
+   return 0;
+   
+#else /* not WHOLE_PAGE_ALLOCATIONS */
+
+   BLOCK_HDR* blk=address_to_block(Addr);
+   
+   if (blk->Magic != BLOCK_HDR_USED_MAGIC)
+      KEBUGCHECK(0);
+   if (blk->Magic == BLOCK_HDR_FREE_MAGIC)
+      KEBUGCHECK(0);
+   
+   return blk->Used.Tag;
+
+#endif /* WHOLE_PAGE_ALLOCATIONS */
+}
+
 VOID STDCALL ExFreeNonPagedPool (PVOID block)
 /*
  * FUNCTION: Releases previously allocated memory

Modified: trunk/reactos/ntoskrnl/ntoskrnl.mc
--- trunk/reactos/ntoskrnl/ntoskrnl.mc	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/ntoskrnl.mc	2005-05-05 17:20:10 UTC (rev 15008)
@@ -987,6 +987,14 @@
 INVALID_WORK_QUEUE_ITEM
 .
 
+MessageId=0xC2
+Severity=Success
+Facility=System
+SymbolicName=BAD_POOL_CALLER
+Language=English
+BAD_POOL_CALLER
+.
+
 MessageId=0xE1
 Severity=Success
 Facility=System

Modified: trunk/reactos/ntoskrnl/ob/object.c
--- trunk/reactos/ntoskrnl/ob/object.c	2005-05-05 16:16:28 UTC (rev 15007)
+++ trunk/reactos/ntoskrnl/ob/object.c	2005-05-05 17:20:10 UTC (rev 15008)
@@ -507,7 +507,7 @@
 
   if (current)
      RtlpCreateUnicodeString (RemainingPath, current, NonPagedPool);
-  RtlFreeUnicodeString (&PathString);
+  ExFreePool(PathString.Buffer);
   *ReturnedObject = CurrentObject;
 
   return STATUS_SUCCESS;
@@ -806,7 +806,7 @@
 	    }
 	  RtlFreeUnicodeString(&Header->Name);
 	  RtlFreeUnicodeString(&RemainingPath);
-	  ExFreePool(Header);
+	  ExFreePoolWithTag(Header, Header->ObjectType->Tag);
 	  DPRINT("Create Failed\n");
 	  return Status;
 	}
@@ -1000,7 +1000,7 @@
     }
 
   DPRINT("ObPerformRetentionChecks() = Freeing object\n");
-  ExFreePool(Header);
+  ExFreePoolWithTag(Header, Header->ObjectType->Tag);
 
   return(STATUS_SUCCESS);
 }
@@ -1010,16 +1010,14 @@
 ObpDeleteObjectWorkRoutine (IN PVOID Parameter)
 {
   PRETENTION_CHECK_PARAMS Params = (PRETENTION_CHECK_PARAMS)Parameter;
-  /* ULONG Tag; */ /* See below */
+  ULONG Tag;
 
   ASSERT(Params);
   ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL); /* We need PAGED_CODE somewhere... */
 
-  /* Turn this on when we have ExFreePoolWithTag
-  Tag = Params->ObjectHeader->ObjectType->Tag; */
+  Tag = Params->ObjectHeader->ObjectType->Tag;
   ObpDeleteObject(Params->ObjectHeader);
-  ExFreePool(Params);
-  /* ExFreePoolWithTag(Params, Tag); */
+  ExFreePoolWithTag(Params, Tag); 
 }