mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[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. svn path=/trunk/; revision=75527
This commit is contained in:
parent
bfac984256
commit
e7fb5e7c33
4 changed files with 36 additions and 34 deletions
|
@ -142,7 +142,7 @@ LogfAllocAndBuildNewRecord(PSIZE_T pRecSize,
|
|||
|
||||
static __inline void LogfFreeRecord(PEVENTLOGRECORD Record)
|
||||
{
|
||||
HeapFree(GetProcessHeap(), 0, Record);
|
||||
RtlFreeHeap(GetProcessHeap(), 0, Record);
|
||||
}
|
||||
|
||||
VOID
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue