[EVTLIB]: Allow specifying a memory allocation tag when freeing the allocated buffers...
authorhbelusca <hbelusca@97493ccd-5924-5043-b1f5-66cb403b36ce>
Fri, 11 Aug 2017 12:37:15 +0000 (12:37 +0000)
committerhbelusca <hbelusca@97493ccd-5924-5043-b1f5-66cb403b36ce>
Fri, 11 Aug 2017 12:37:15 +0000 (12:37 +0000)
[EVENTLOG]: Use the previous functionality; use also the internal LogfpAlloc() / LogfpFree() functions when dealing with buffers related to event log files.

git-svn-id: file:///srv/svn/reactos/trunk@75527 97493ccd-5924-5043-b1f5-66cb403b36ce

reactos/base/services/eventlog/eventlog.h
reactos/base/services/eventlog/file.c
reactos/sdk/lib/evtlib/evtlib.c
reactos/sdk/lib/evtlib/evtlib.h

index b13ef6d..b57f675 100644 (file)
@@ -142,7 +142,7 @@ LogfAllocAndBuildNewRecord(PSIZE_T pRecSize,
 
 static __inline void LogfFreeRecord(PEVENTLOGRECORD Record)
 {
-    HeapFree(GetProcessHeap(), 0, Record);
+    RtlFreeHeap(GetProcessHeap(), 0, Record);
 }
 
 VOID
index 6646e61..5301502 100644 (file)
@@ -167,8 +167,10 @@ LogfpAlloc(IN SIZE_T Size,
 static
 VOID NTAPI
 LogfpFree(IN PVOID Ptr,
-          IN ULONG Flags)
+          IN ULONG Flags,
+          IN ULONG Tag)
 {
+    UNREFERENCED_PARAMETER(Tag);
     RtlFreeHeap(GetProcessHeap(), Flags, Ptr);
 }
 
@@ -305,7 +307,7 @@ LogfCreate(PLOGFILE* LogFile,
     SIZE_T LogNameLen;
     BOOLEAN CreateNew;
 
-    pLogFile = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pLogFile));
+    pLogFile = LogfpAlloc(sizeof(*pLogFile), HEAP_ZERO_MEMORY, TAG_ELF);
     if (!pLogFile)
     {
         DPRINT1("Cannot allocate heap!\n");
@@ -313,9 +315,7 @@ LogfCreate(PLOGFILE* LogFile,
     }
 
     LogNameLen = (LogName ? wcslen(LogName) : 0) + 1;
-    pLogFile->LogName = RtlAllocateHeap(GetProcessHeap(),
-                                        HEAP_ZERO_MEMORY,
-                                        LogNameLen * sizeof(WCHAR));
+    pLogFile->LogName = LogfpAlloc(LogNameLen * sizeof(WCHAR), HEAP_ZERO_MEMORY, 0);
     if (pLogFile->LogName == NULL)
     {
         DPRINT1("Cannot allocate heap\n");
@@ -412,9 +412,9 @@ Quit:
             NtClose(pLogFile->FileHandle);
 
         if (pLogFile->LogName)
-            RtlFreeHeap(GetProcessHeap(), 0, pLogFile->LogName);
+            LogfpFree(pLogFile->LogName, 0, 0);
 
-        RtlFreeHeap(GetProcessHeap(), 0, pLogFile);
+        LogfpFree(pLogFile, 0, TAG_ELF);
     }
     else
     {
@@ -440,11 +440,11 @@ LogfClose(PLOGFILE LogFile,
 
     ElfCloseFile(&LogFile->LogFile);
     NtClose(LogFile->FileHandle);
-    RtlFreeHeap(GetProcessHeap(), 0, LogFile->LogName);
+    LogfpFree(LogFile->LogName, 0, 0);
 
     RtlDeleteResource(&LogFile->Lock);
 
-    RtlFreeHeap(GetProcessHeap(), 0, LogFile);
+    LogfpFree(LogFile, 0, TAG_ELF);
 
     return;
 }
@@ -583,7 +583,7 @@ ReadRecord(IN  PEVTLOGFILE LogFile,
     if (BytesNeeded)
         *BytesNeeded = 0;
 
-    UnicodeBuffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, BufSize);
+    UnicodeBuffer = LogfpAlloc(BufSize, HEAP_ZERO_MEMORY, TAG_ELF_BUF);
     if (UnicodeBuffer == NULL)
     {
         DPRINT1("Alloc failed!\n");
@@ -705,7 +705,7 @@ ReadRecord(IN  PEVTLOGFILE LogFile,
     Status = STATUS_SUCCESS;
 
 Quit:
-    RtlFreeHeap(GetProcessHeap(), 0, UnicodeBuffer);
+    LogfpFree(UnicodeBuffer, 0, TAG_ELF_BUF);
 
     return Status;
 }
index fa0b60e..a11c070 100644 (file)
@@ -2,8 +2,8 @@
  * PROJECT:         ReactOS EventLog File Library
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            sdk/lib/evtlib/evtlib.c
- * PURPOSE:         Provides a library for reading and writing EventLog files
- *                  in the NT <= 5.2 (.evt) format.
+ * PURPOSE:         Provides functionality for reading and writing
+ *                  EventLog files in the NT <= 5.2 (.evt) format.
  * PROGRAMMERS:     Copyright 2005 Saveliy Tretiakov
  *                  Michael Martin
  *                  Hermes Belusca-Maito
@@ -238,7 +238,7 @@ ElfpAddOffsetInformation(
             RtlCopyMemory(NewOffsetInfo,
                           LogFile->OffsetInfo,
                           LogFile->OffsetInfoSize * sizeof(EVENT_OFFSET_INFO));
-            LogFile->Free(LogFile->OffsetInfo, 0);
+            LogFile->Free(LogFile->OffsetInfo, 0, TAG_ELF);
         }
         LogFile->OffsetInfo = (PEVENT_OFFSET_INFO)NewOffsetInfo;
         LogFile->OffsetInfoSize += OFFSET_INFO_INCREMENT;
@@ -771,20 +771,20 @@ Continue:
         if (!NT_SUCCESS(Status))
         {
             EVTLTRACE1("ReadLogBuffer failed (Status 0x%08lx)\n", Status);
-            LogFile->Free(pRecBuf, 0);
+            LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
             return STATUS_EVENTLOG_FILE_CORRUPT;
         }
         if (ReadLength != RecBuf.Length)
         {
             DPRINT1("Oh oh!!\n");
-            LogFile->Free(pRecBuf, 0);
+            LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
             break;
         }
 
         // /* If OverWrittenRecords is TRUE and this record has already been read */
         // if (OverWrittenRecords && (pRecBuf->RecordNumber == LogFile->Header.OldestRecordNumber))
         // {
-            // LogFile->Free(pRecBuf, 0);
+            // LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
             // break;
         // }
 
@@ -794,7 +794,7 @@ Continue:
         {
             EVTLTRACE1("Invalid RecordSizeEnd of record %d (0x%x) in `%wZ'\n",
                     RecordNumber, *pRecSize2, &LogFile->FileName);
-            LogFile->Free(pRecBuf, 0);
+            LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
             break;
         }
 
@@ -807,11 +807,11 @@ Continue:
                                       FileOffset.QuadPart))
         {
             EVTLTRACE1("ElfpAddOffsetInformation() failed!\n");
-            LogFile->Free(pRecBuf, 0);
+            LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
             return STATUS_EVENTLOG_FILE_CORRUPT;
         }
 
-        LogFile->Free(pRecBuf, 0);
+        LogFile->Free(pRecBuf, 0, TAG_ELF_BUF);
 
         if (NextOffset.QuadPart == LogFile->Header.EndOffset)
         {
@@ -874,7 +874,7 @@ Continue:
 NTSTATUS
 NTAPI
 ElfCreateFile(
-    IN PEVTLOGFILE LogFile,
+    IN OUT PEVTLOGFILE LogFile,
     IN PUNICODE_STRING FileName OPTIONAL,
     IN ULONG    FileSize,
     IN ULONG    MaxSize,
@@ -952,14 +952,13 @@ Quit:
     if (!NT_SUCCESS(Status))
     {
         if (LogFile->OffsetInfo)
-            LogFile->Free(LogFile->OffsetInfo, 0);
+            LogFile->Free(LogFile->OffsetInfo, 0, TAG_ELF);
 
         if (LogFile->FileName.Buffer)
-            LogFile->Free(LogFile->FileName.Buffer, 0);
+            LogFile->Free(LogFile->FileName.Buffer, 0, TAG_ELF);
     }
 
     return Status;
-
 }
 
 NTSTATUS
@@ -1071,7 +1070,7 @@ ElfBackupFile(
         if (!NT_SUCCESS(Status))
         {
             EVTLTRACE1("ReadLogBuffer failed (Status 0x%08lx)\n", Status);
-            LogFile->Free(Buffer, 0);
+            LogFile->Free(Buffer, 0, TAG_ELF_BUF);
             // Status = STATUS_EVENTLOG_FILE_CORRUPT;
             goto Quit;
         }
@@ -1085,7 +1084,7 @@ ElfBackupFile(
         if (!NT_SUCCESS(Status))
         {
             EVTLTRACE1("FileWrite() failed (Status 0x%08lx)\n", Status);
-            LogFile->Free(Buffer, 0);
+            LogFile->Free(Buffer, 0, TAG_ELF_BUF);
             goto Quit;
         }
 
@@ -1093,7 +1092,7 @@ ElfBackupFile(
         Header->EndOffset += RecBuf.Length;
 
         /* Free the buffer */
-        LogFile->Free(Buffer, 0);
+        LogFile->Free(Buffer, 0, TAG_ELF_BUF);
         Buffer = NULL;
     }
 
@@ -1186,10 +1185,10 @@ ElfCloseFile(  // ElfFree
     ElfFlushFile(LogFile);
 
     /* Free the data */
-    LogFile->Free(LogFile->OffsetInfo, 0);
+    LogFile->Free(LogFile->OffsetInfo, 0, TAG_ELF);
 
     if (LogFile->FileName.Buffer)
-        LogFile->Free(LogFile->FileName.Buffer, 0);
+        LogFile->Free(LogFile->FileName.Buffer, 0, TAG_ELF);
     RtlInitEmptyUnicodeString(&LogFile->FileName, NULL, 0);
 }
 
index ce13fd0..66b7a0f 100644 (file)
@@ -2,8 +2,8 @@
  * PROJECT:         ReactOS EventLog File Library
  * LICENSE:         GPL - See COPYING in the top level directory
  * FILE:            sdk/lib/evtlib/evtlib.h
- * PURPOSE:         Provides a library for reading and writing EventLog files
- *                  in the NT <= 5.2 (.evt) format.
+ * PURPOSE:         Provides functionality for reading and writing
+ *                  EventLog files in the NT <= 5.2 (.evt) format.
  * PROGRAMMERS:     Copyright 2005 Saveliy Tretiakov
  *                  Michael Martin
  *                  Hermes Belusca-Maito
@@ -12,6 +12,8 @@
 #ifndef __EVTLIB_H__
 #define __EVTLIB_H__
 
+#pragma once
+
 /* PSDK/NDK Headers */
 // #define WIN32_NO_STATUS
 // #include <windef.h>
@@ -157,7 +159,8 @@ typedef PVOID
 typedef VOID
 (NTAPI *PELF_FREE_ROUTINE)(
     IN PVOID Ptr,
-    IN ULONG Flags
+    IN ULONG Flags,
+    IN ULONG Tag
 );
 
 typedef NTSTATUS
@@ -214,7 +217,7 @@ typedef struct _EVTLOGFILE
 NTSTATUS
 NTAPI
 ElfCreateFile(
-    IN PEVTLOGFILE LogFile,
+    IN OUT PEVTLOGFILE LogFile,
     IN PUNICODE_STRING FileName OPTIONAL,
     IN ULONG    FileSize,
     IN ULONG    MaxSize,