Author: hbelusca
Date: Fri Aug 11 12:37:15 2017
New Revision: 75527
URL:
http://svn.reactos.org/svn/reactos?rev=75527&view=rev
Log:
[EVTLIB]: Allow specifying a memory allocation tag when freeing the allocated buffers
(functionality similar to the Ex**WithTag kernel functions).
[EVENTLOG]: Use the previous functionality; use also the internal LogfpAlloc() /
LogfpFree() functions when dealing with buffers related to event log files.
Modified:
trunk/reactos/base/services/eventlog/eventlog.h
trunk/reactos/base/services/eventlog/file.c
trunk/reactos/sdk/lib/evtlib/evtlib.c
trunk/reactos/sdk/lib/evtlib/evtlib.h
Modified: trunk/reactos/base/services/eventlog/eventlog.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/eve…
==============================================================================
--- trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/eventlog.h [iso-8859-1] Fri Aug 11 12:37:15 2017
@@ -142,7 +142,7 @@
static __inline void LogfFreeRecord(PEVENTLOGRECORD Record)
{
- HeapFree(GetProcessHeap(), 0, Record);
+ RtlFreeHeap(GetProcessHeap(), 0, Record);
}
VOID
Modified: trunk/reactos/base/services/eventlog/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/services/eventlog/fil…
==============================================================================
--- trunk/reactos/base/services/eventlog/file.c [iso-8859-1] (original)
+++ trunk/reactos/base/services/eventlog/file.c [iso-8859-1] Fri Aug 11 12:37:15 2017
@@ -167,8 +167,10 @@
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 @@
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 @@
}
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 @@
NtClose(pLogFile->FileHandle);
if (pLogFile->LogName)
- RtlFreeHeap(GetProcessHeap(), 0, pLogFile->LogName);
-
- RtlFreeHeap(GetProcessHeap(), 0, pLogFile);
+ LogfpFree(pLogFile->LogName, 0, 0);
+
+ LogfpFree(pLogFile, 0, TAG_ELF);
}
else
{
@@ -440,11 +440,11 @@
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 @@
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 @@
Status = STATUS_SUCCESS;
Quit:
- RtlFreeHeap(GetProcessHeap(), 0, UnicodeBuffer);
+ LogfpFree(UnicodeBuffer, 0, TAG_ELF_BUF);
return Status;
}
Modified: trunk/reactos/sdk/lib/evtlib/evtlib.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/evtlib/evtlib.c?re…
==============================================================================
--- trunk/reactos/sdk/lib/evtlib/evtlib.c [iso-8859-1] (original)
+++ trunk/reactos/sdk/lib/evtlib/evtlib.c [iso-8859-1] Fri Aug 11 12:37:15 2017
@@ -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 @@
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 @@
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 @@
{
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
Header->EndOffset += RecBuf.Length;
/* Free the buffer */
- LogFile->Free(Buffer, 0);
+ LogFile->Free(Buffer, 0, TAG_ELF_BUF);
Buffer = NULL;
}
@@ -1186,10 +1185,10 @@
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);
}
Modified: trunk/reactos/sdk/lib/evtlib/evtlib.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/sdk/lib/evtlib/evtlib.h?re…
==============================================================================
--- trunk/reactos/sdk/lib/evtlib/evtlib.h [iso-8859-1] (original)
+++ trunk/reactos/sdk/lib/evtlib/evtlib.h [iso-8859-1] Fri Aug 11 12:37:15 2017
@@ -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
@@ -11,6 +11,8 @@
#ifndef __EVTLIB_H__
#define __EVTLIB_H__
+
+#pragma once
/* PSDK/NDK Headers */
// #define WIN32_NO_STATUS
@@ -157,7 +159,8 @@
typedef VOID
(NTAPI *PELF_FREE_ROUTINE)(
IN PVOID Ptr,
- IN ULONG Flags
+ IN ULONG Flags,
+ IN ULONG Tag
);
typedef NTSTATUS
@@ -214,7 +217,7 @@
NTSTATUS
NTAPI
ElfCreateFile(
- IN PEVTLOGFILE LogFile,
+ IN OUT PEVTLOGFILE LogFile,
IN PUNICODE_STRING FileName OPTIONAL,
IN ULONG FileSize,
IN ULONG MaxSize,