[ros-diffs] [reactos] 01/01: [SNDVOL32] Implement the dialog resize code for the 'Advanced Controls' menu item and prepare for clicks on the 'Advanced' button.

2019-02-17 Thread Eric Kohl
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=95ed44ef63d767a2bda03fef455b795526f265aa

commit 95ed44ef63d767a2bda03fef455b795526f265aa
Author: Eric Kohl 
AuthorDate: Mon Feb 18 00:58:28 2019 +0100
Commit: Eric Kohl 
CommitDate: Mon Feb 18 00:58:28 2019 +0100

[SNDVOL32] Implement the dialog resize code for the 'Advanced Controls' 
menu item and prepare for clicks on the 'Advanced' button.
---
 base/applications/sndvol32/dialog.c   |  52 ++--
 base/applications/sndvol32/sndvol32.c | 108 +++---
 base/applications/sndvol32/sndvol32.h |   2 +
 3 files changed, 69 insertions(+), 93 deletions(-)

diff --git a/base/applications/sndvol32/dialog.c 
b/base/applications/sndvol32/dialog.c
index d14a324098..f0d5d39a84 100644
--- a/base/applications/sndvol32/dialog.c
+++ b/base/applications/sndvol32/dialog.c
@@ -631,7 +631,19 @@ EnumConnectionsCallback(
   else
   {
   if (PrefContext->MixerWindow->Mode == NORMAL_MODE)
+  {
   PrefContext->MixerWindow->bHasExtendedControls = 
TRUE;
+
+  wID = (PrefContext->MixerWindow->DialogCount + 
1) * IDC_LINE_ADVANCED;
+
+  /* get dialog control */
+  hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
+  if (hDlgCtrl != NULL)
+  {
+  ShowWindow(hDlgCtrl,
+ 
PrefContext->MixerWindow->bShowExtendedControls ? SW_SHOWNORMAL : SW_HIDE);
+  }
+  }
   }
   }
 
@@ -658,26 +670,34 @@ LoadDialogCtrls(
 {
 HWND hDlgCtrl;
 RECT statusRect;
+UINT i;
+LONG dy;
 
 /* set dialog count to zero */
 PrefContext->MixerWindow->DialogCount = 0;
-
+PrefContext->MixerWindow->bHasExtendedControls = FALSE;
 SetRectEmpty(>MixerWindow->rect);
 
 /* enumerate controls */
 SndMixerEnumConnections(PrefContext->MixerWindow->Mixer, 
PrefContext->SelectedLine, EnumConnectionsCallback, (PVOID)PrefContext);
 
-if (PrefContext->MixerWindow->bHasExtendedControls)
-{
-EnableMenuItem(GetMenu(PrefContext->MixerWindow->hWnd), 
IDM_ADVANCED_CONTROLS, MF_BYCOMMAND | MF_ENABLED);
-}
+/* Update the 'Advanced Controls' menu item */
+EnableMenuItem(GetMenu(PrefContext->MixerWindow->hWnd),
+   IDM_ADVANCED_CONTROLS,
+   MF_BYCOMMAND | 
(PrefContext->MixerWindow->bHasExtendedControls ? MF_ENABLED : MF_GRAYED));
 
+/* Add some height for the status bar */
 if (PrefContext->MixerWindow->hStatusBar)
 {
 GetWindowRect(PrefContext->MixerWindow->hStatusBar, );
 PrefContext->MixerWindow->rect.bottom += (statusRect.bottom - 
statusRect.top);
 }
 
+/* Add height of the 'Advanced' button */
+dy = MulDiv(ADVANCED_BUTTON_HEIGHT, PrefContext->MixerWindow->baseUnit.cy, 
8);
+if (PrefContext->MixerWindow->bShowExtendedControls && 
PrefContext->MixerWindow->bHasExtendedControls)
+PrefContext->MixerWindow->rect.bottom += dy;
+
 /* now move the window */
 AdjustWindowRect(>MixerWindow->rect, WS_DLGFRAME | WS_CAPTION 
| WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, 
TRUE);
 SetWindowPos(PrefContext->MixerWindow->hWnd, HWND_TOP, 
PrefContext->MixerWindow->rect.left, PrefContext->MixerWindow->rect.top, 
PrefContext->MixerWindow->rect.right - PrefContext->MixerWindow->rect.left, 
PrefContext->MixerWindow->rect.bottom - PrefContext->MixerWindow->rect.top, 
SWP_NOMOVE | SWP_NOZORDER);
@@ -694,8 +714,28 @@ LoadDialogCtrls(
  SWP_NOZORDER);
 }
 
+/* Resize the vertical line separators */
+for (i = 0; i < PrefContext->MixerWindow->DialogCount; i++)
+{
+hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, (i + 1) * 
IDC_LINE_SEP);
+if (hDlgCtrl != NULL)
+{
+GetWindowRect(hDlgCtrl, );
+if (PrefContext->MixerWindow->bShowExtendedControls && 
PrefContext->MixerWindow->bHasExtendedControls)
+statusRect.bottom += dy;
+
+SetWindowPos(hDlgCtrl,
+ HWND_TOP,
+ 0,
+ 0,
+ statusRect.right - statusRect.left,
+ statusRect.bottom - statusRect.top,
+ SWP_NOMOVE | SWP_NOZORDER);
+}
+}
+
 /* Hide the last line separator */
-hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, IDC_LINE_SEP * 
PrefContext->MixerWindow->DialogCount /*PrefContext->Count*/);
+hDlgCtrl = GetDlgItem(PrefContext->MixerWindow->hWnd, IDC_LINE_SEP * 
PrefContext->MixerWindow->DialogCount);
 if (hDlgCtrl != NULL)
 {
 

[ros-diffs] [reactos] 01/01: [SNDVOL32] Fix the window height issue when the line selection changes and implement the 'Advanced Controls' menu item.

2019-02-17 Thread Eric Kohl
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fe5c50e1820351e4bfcb8c136e5cab06c3eb8a2b

commit fe5c50e1820351e4bfcb8c136e5cab06c3eb8a2b
Author: Eric Kohl 
AuthorDate: Sun Feb 17 14:04:39 2019 +0100
Commit: Eric Kohl 
CommitDate: Sun Feb 17 14:04:39 2019 +0100

[SNDVOL32] Fix the window height issue when the line selection changes and 
implement the 'Advanced Controls' menu item.

CORE-9108 CORE-15751
---
 base/applications/sndvol32/dialog.c  |  55 -
 base/applications/sndvol32/lang/bg-BG.rc |  10 +--
 base/applications/sndvol32/lang/cs-CZ.rc |  10 +--
 base/applications/sndvol32/lang/de-DE.rc |  10 +--
 base/applications/sndvol32/lang/el-GR.rc |  10 +--
 base/applications/sndvol32/lang/en-US.rc |  10 +--
 base/applications/sndvol32/lang/es-ES.rc |  10 +--
 base/applications/sndvol32/lang/fr-FR.rc |  10 +--
 base/applications/sndvol32/lang/he-IL.rc |  10 +--
 base/applications/sndvol32/lang/hu-HU.rc |  10 +--
 base/applications/sndvol32/lang/id-ID.rc |  10 +--
 base/applications/sndvol32/lang/it-IT.rc |  10 +--
 base/applications/sndvol32/lang/ja-JP.rc |  10 +--
 base/applications/sndvol32/lang/ko-KR.rc |  10 +--
 base/applications/sndvol32/lang/lt-LT.rc |  10 +--
 base/applications/sndvol32/lang/nl-NL.rc |  10 +--
 base/applications/sndvol32/lang/no-NO.rc |  10 +--
 base/applications/sndvol32/lang/pl-PL.rc |  10 +--
 base/applications/sndvol32/lang/pt-BR.rc |  10 +--
 base/applications/sndvol32/lang/ro-RO.rc |  10 +--
 base/applications/sndvol32/lang/ru-RU.rc |  10 +--
 base/applications/sndvol32/lang/sk-SK.rc |  10 +--
 base/applications/sndvol32/lang/sq-AL.rc |  10 +--
 base/applications/sndvol32/lang/sv-SE.rc |  10 +--
 base/applications/sndvol32/lang/th-TH.rc |  10 +--
 base/applications/sndvol32/lang/tr-TR.rc |  10 +--
 base/applications/sndvol32/lang/uk-UA.rc |  10 +--
 base/applications/sndvol32/lang/zh-CN.rc |  10 +--
 base/applications/sndvol32/lang/zh-TW.rc |  10 +--
 base/applications/sndvol32/resources.h   |   3 +-
 base/applications/sndvol32/sndvol32.c| 103 +++
 base/applications/sndvol32/sndvol32.h|   5 +-
 32 files changed, 305 insertions(+), 141 deletions(-)

diff --git a/base/applications/sndvol32/dialog.c 
b/base/applications/sndvol32/dialog.c
index 9aed047faf..d14a324098 100644
--- a/base/applications/sndvol32/dialog.c
+++ b/base/applications/sndvol32/dialog.c
@@ -225,7 +225,7 @@ AddDialogControl(
 }
 else if (!wcsicmp(ClassName, L"button"))
 {
-if (DialogItem->style & BS_AUTOCHECKBOX)
+if (DialogItem->id == IDC_LINE_SWITCH)
 {
 if (MixerId == PLAY_MIXER)
 {
@@ -233,13 +233,15 @@ AddDialogControl(
 EnableWindow(hwnd, FALSE);
 }
 }
+else if (DialogItem->id == IDC_LINE_ADVANCED)
+{
+ShowWindow(hwnd, SW_HIDE);
+}
 
 /* Set font */
 SendMessageW(hwnd, WM_SETFONT, (WPARAM)hFont, TRUE);
 }
 
-//ShowWindow(hwnd, SW_SHOWNORMAL);
-
 if (WindowName != NULL)
 {
 /* move offset past window name */
@@ -396,6 +398,9 @@ LoadDialog(
 yBaseUnit = charSize.cy;
 }
 SelectObject(hDC, hOldFont);
+
+MixerWindow->baseUnit.cx = charSize.cx;
+MixerWindow->baseUnit.cy = charSize.cy;
 }
 }
 
@@ -480,10 +485,10 @@ EnumConnectionsCallback(
   dlgId = (PrefContext->MixerWindow->Mode == SMALL_MODE) ? 
IDD_SMALL_LINE : IDD_NORMAL_LINE;
 
   /* load dialog resource */
-  LoadDialog(hAppInstance, PrefContext->MixerWindow, 
MAKEINTRESOURCE(dlgId), PrefContext->Count);
+  LoadDialog(hAppInstance, PrefContext->MixerWindow, 
MAKEINTRESOURCE(dlgId), PrefContext->MixerWindow->DialogCount);
 
   /* get id */
-  wID = (PrefContext->Count + 1) * IDC_LINE_NAME;
+  wID = (PrefContext->MixerWindow->DialogCount + 1) * 
IDC_LINE_NAME;
 
   /* set line name */
   SetDlgItemTextW(PrefContext->MixerWindow->hWnd, wID, 
Line->szName);
@@ -502,7 +507,7 @@ EnumConnectionsCallback(
   if (SndMixerGetVolumeControlDetails(Mixer, 
Control[Index].dwControlID, 1, sizeof(MIXERCONTROLDETAILS_BOOLEAN), 
(LPVOID)) != -1)
   {
   /* update dialog control */
-  wID = (PrefContext->Count + 1) * IDC_LINE_SWITCH;
+  wID = (PrefContext->MixerWindow->DialogCount + 
1) * IDC_LINE_SWITCH;
 
   /* get dialog control */
   hDlgCtrl = 
GetDlgItem(PrefContext->MixerWindow->hWnd, wID);
@@ -578,7 +583,7 @@ EnumConnectionsCallback(
   }
 
   /* Set the volume trackbar */
-  wID = (PrefContext->Count + 1) * 
IDC_LINE_SLIDER_VERT;
+  wID 

[ros-diffs] [reactos] 01/01: [RTL] Fix GCC build.

2019-02-17 Thread Thomas Faber
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=a951d66002fd3ce99f1de2f241515303a93012e4

commit a951d66002fd3ce99f1de2f241515303a93012e4
Author: Thomas Faber 
AuthorDate: Sun Feb 17 09:58:28 2019 +0100
Commit: Thomas Faber 
CommitDate: Sun Feb 17 09:59:49 2019 +0100

[RTL] Fix GCC build.
---
 sdk/lib/rtl/heap.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sdk/lib/rtl/heap.c b/sdk/lib/rtl/heap.c
index 4d47ee2ec9..4c51053e65 100644
--- a/sdk/lib/rtl/heap.c
+++ b/sdk/lib/rtl/heap.c
@@ -2204,6 +2204,7 @@ BOOLEAN NTAPI RtlFreeHeap(
 RtlSetLastWin32ErrorAndNtStatusFromNtStatus(STATUS_INVALID_PARAMETER);
 _SEH2_YIELD(return FALSE);
 }
+_SEH2_END;
 
 /* Lock if necessary */
 if (!(Flags & HEAP_NO_SERIALIZE))



[ros-diffs] [reactos] 04/04: [ACPI] Update ACPICA library to version 20190215.

2019-02-17 Thread Thomas Faber
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9d53c935f22775e45f2cb980df86eecb1c81fd36

commit 9d53c935f22775e45f2cb980df86eecb1c81fd36
Author: Thomas Faber 
AuthorDate: Fri Feb 15 19:43:25 2019 +0100
Commit: Thomas Faber 
CommitDate: Sun Feb 17 09:51:20 2019 +0100

[ACPI] Update ACPICA library to version 20190215.
---
 drivers/bus/acpi/acpica/dispatcher/dsfield.c |   6 +
 drivers/bus/acpi/acpica/dispatcher/dsopcode.c|  13 +-
 drivers/bus/acpi/acpica/dispatcher/dswload2.c|   2 +-
 drivers/bus/acpi/acpica/events/evgpe.c   |   2 +-
 drivers/bus/acpi/acpica/events/evregion.c|   2 +-
 drivers/bus/acpi/acpica/events/evrgnini.c|  18 ---
 drivers/bus/acpi/acpica/events/evxfgpe.c |   4 +-
 drivers/bus/acpi/acpica/executer/exconvrt.c  |   2 +-
 drivers/bus/acpi/acpica/executer/exfield.c   |  62 +++
 drivers/bus/acpi/acpica/executer/exserial.c  |   2 +-
 drivers/bus/acpi/acpica/executer/exutils.c   |   2 +-
 drivers/bus/acpi/acpica/include/acclib.h |   2 +-
 drivers/bus/acpi/acpica/include/acconfig.h   |   2 +-
 drivers/bus/acpi/acpica/include/acdebug.h|   3 +-
 drivers/bus/acpi/acpica/include/acdisasm.h   |   2 +
 drivers/bus/acpi/acpica/include/acexcep.h|   2 +-
 drivers/bus/acpi/acpica/include/aclocal.h|   2 +-
 drivers/bus/acpi/acpica/include/acmacros.h   |   2 +-
 drivers/bus/acpi/acpica/include/acobject.h   |   1 +
 drivers/bus/acpi/acpica/include/acpixf.h |  10 +-
 drivers/bus/acpi/acpica/include/acpredef.h   |  15 ++
 drivers/bus/acpi/acpica/include/acrestyp.h   |  14 +-
 drivers/bus/acpi/acpica/include/actbinfo.h   |   7 +-
 drivers/bus/acpi/acpica/include/actbl1.h |  20 ++-
 drivers/bus/acpi/acpica/include/actbl2.h |  15 +-
 drivers/bus/acpi/acpica/include/actbl3.h |  23 ++-
 drivers/bus/acpi/acpica/include/actypes.h|   3 +-
 drivers/bus/acpi/acpica/include/platform/acefi.h |   2 +-
 drivers/bus/acpi/acpica/namespace/nsload.c   |   2 +-
 drivers/bus/acpi/acpica/namespace/nsparse.c  |  70 ++--
 drivers/bus/acpi/acpica/namespace/nsutils.c  |   2 +-
 drivers/bus/acpi/acpica/parser/psloop.c  | 195 ---
 drivers/bus/acpi/acpica/parser/psparse.c |   4 +-
 drivers/bus/acpi/acpica/resources/rsdumpinfo.c   |  14 +-
 drivers/bus/acpi/acpica/resources/rsirq.c|   8 +-
 drivers/bus/acpi/acpica/resources/rsserial.c |  10 +-
 drivers/bus/acpi/acpica/tables/tbfadt.c  |   2 +-
 drivers/bus/acpi/acpica/tables/tbxface.c |   4 +-
 drivers/bus/acpi/acpica/tables/tbxfload.c|  26 ++-
 drivers/bus/acpi/acpica/utilities/utclib.c   |   4 +-
 drivers/bus/acpi/acpica/utilities/utdecode.c |   5 +-
 drivers/bus/acpi/acpica/utilities/utdelete.c |   5 +
 drivers/bus/acpi/acpica/utilities/uterror.c  |   9 +-
 drivers/bus/acpi/buspdo.c|   8 +-
 44 files changed, 236 insertions(+), 372 deletions(-)

diff --git a/drivers/bus/acpi/acpica/dispatcher/dsfield.c 
b/drivers/bus/acpi/acpica/dispatcher/dsfield.c
index 44e2889b12..ec1c125449 100644
--- a/drivers/bus/acpi/acpica/dispatcher/dsfield.c
+++ b/drivers/bus/acpi/acpica/dispatcher/dsfield.c
@@ -577,6 +577,12 @@ AcpiDsCreateField (
 Info.RegionNode = RegionNode;
 
 Status = AcpiDsGetFieldNames (, WalkState, Arg->Common.Next);
+if (Info.RegionNode->Type == ACPI_ADR_SPACE_PLATFORM_COMM &&
+!(RegionNode->Object->Field.InternalPccBuffer
+= ACPI_ALLOCATE_ZEROED(Info.RegionNode->Object->Region.Length)))
+{
+return_ACPI_STATUS (AE_NO_MEMORY);
+}
 return_ACPI_STATUS (Status);
 }
 
diff --git a/drivers/bus/acpi/acpica/dispatcher/dsopcode.c 
b/drivers/bus/acpi/acpica/dispatcher/dsopcode.c
index 97d6b3f5e6..1d35c5be77 100644
--- a/drivers/bus/acpi/acpica/dispatcher/dsopcode.c
+++ b/drivers/bus/acpi/acpica/dispatcher/dsopcode.c
@@ -413,6 +413,7 @@ AcpiDsEvalRegionOperands (
 ACPI_OPERAND_OBJECT *OperandDesc;
 ACPI_NAMESPACE_NODE *Node;
 ACPI_PARSE_OBJECT   *NextOp;
+ACPI_ADR_SPACE_TYPE SpaceId;
 
 
 ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
@@ -422,11 +423,12 @@ AcpiDsEvalRegionOperands (
  * This is where we evaluate the address and length fields of the
  * OpRegion declaration
  */
-Node =  Op->Common.Node;
+Node = Op->Common.Node;
 
 /* NextOp points to the op that holds the SpaceID */
 
 NextOp = Op->Common.Value.Arg;
+SpaceId = (ACPI_ADR_SPACE_TYPE) NextOp->Common.Value.Integer;
 
 /* NextOp points to address op */
 
@@ -464,6 +466,15 @@ AcpiDsEvalRegionOperands (
 ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
 AcpiUtRemoveReference (OperandDesc);
 
+/* A zero-length operation region is unusable. Just warn */
+
+if (!ObjDesc->Region.Length && (SpaceId < ACPI_NUM_PREDEFINED_REGIONS))
+{
+ACPI_WARNING ((AE_INFO,
+

[ros-diffs] [reactos] 03/04: [COMCTL32] Check for NULL pointer when handling BCM_GETIDEALSIZE.

2019-02-17 Thread Thomas Faber
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8dcdf82e71c3b032617251ab0ec2024b7f4f820a

commit 8dcdf82e71c3b032617251ab0ec2024b7f4f820a
Author: Thomas Faber 
AuthorDate: Sun Feb 3 16:55:04 2019 +0100
Commit: Thomas Faber 
CommitDate: Sun Feb 17 09:51:18 2019 +0100

[COMCTL32] Check for NULL pointer when handling BCM_GETIDEALSIZE.

Fixes crash in comctl32_winetest:button.
---
 dll/win32/comctl32/button.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/dll/win32/comctl32/button.c b/dll/win32/comctl32/button.c
index 59067471f1..1d7431d0b1 100644
--- a/dll/win32/comctl32/button.c
+++ b/dll/win32/comctl32/button.c
@@ -941,6 +941,11 @@ static LRESULT CALLBACK BUTTON_WindowProc(HWND hWnd, UINT 
uMsg, WPARAM wParam, L
 BOOL ret = FALSE;
 SIZE* pSize = (SIZE*)lParam;
 
+if (!pSize)
+{
+return FALSE;
+}
+
 if (btn_type == BS_PUSHBUTTON || 
 btn_type == BS_DEFPUSHBUTTON ||
 btn_type == BS_USERBUTTON)



[ros-diffs] [reactos] 02/04: [COMCTL32] Add NULL checks to SetWindowSubclass.

2019-02-17 Thread Thomas Faber
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3445129dd314c19b6027532019e0e703f0b77c3a

commit 3445129dd314c19b6027532019e0e703f0b77c3a
Author: Thomas Faber 
AuthorDate: Sun Feb 3 16:41:29 2019 +0100
Commit: Thomas Faber 
CommitDate: Sun Feb 17 09:51:16 2019 +0100

[COMCTL32] Add NULL checks to SetWindowSubclass.

Imports Wine commit 04847e68f87 by Sven Baars.

Fixes crash in comctl32_winetest:subclass.
---
 dll/win32/comctl32/commctrl.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/dll/win32/comctl32/commctrl.c b/dll/win32/comctl32/commctrl.c
index d4cb73ae76..a3bbd5fc31 100644
--- a/dll/win32/comctl32/commctrl.c
+++ b/dll/win32/comctl32/commctrl.c
@@ -1266,6 +1266,9 @@ BOOL WINAPI SetWindowSubclass (HWND hWnd, SUBCLASSPROC 
pfnSubclass,
 
TRACE ("(%p, %p, %lx, %lx)\n", hWnd, pfnSubclass, uIDSubclass, dwRef);
 
+if (!hWnd || !pfnSubclass)
+return FALSE;
+
/* Since the window procedure that we set here has two additional arguments,
 * we can't simply set it as the new window procedure of the window. So we
 * set our own window procedure and then calculate the other two arguments



[ros-diffs] [reactos] 01/04: [RTL] Protect pointer validity check in RtlFreeHeap with SEH.

2019-02-17 Thread Thomas Faber
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7246909a80cdb8dc420981974c21bbbdbf0bd48b

commit 7246909a80cdb8dc420981974c21bbbdbf0bd48b
Author: Thomas Faber 
AuthorDate: Sun Feb 3 13:57:21 2019 +0100
Commit: Thomas Faber 
CommitDate: Sun Feb 17 09:51:12 2019 +0100

[RTL] Protect pointer validity check in RtlFreeHeap with SEH.

Fixes crash in kernel32_winetest:heap.
---
 sdk/lib/rtl/heap.c | 38 +++---
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/sdk/lib/rtl/heap.c b/sdk/lib/rtl/heap.c
index 1c6df2996f..4d47ee2ec9 100644
--- a/sdk/lib/rtl/heap.c
+++ b/sdk/lib/rtl/heap.c
@@ -2180,28 +2180,36 @@ BOOLEAN NTAPI RtlFreeHeap(
 if (RtlpHeapIsSpecial(Flags))
 return RtlDebugFreeHeap(Heap, Flags, Ptr);
 
-/* Lock if necessary */
-if (!(Flags & HEAP_NO_SERIALIZE))
-{
-RtlEnterHeapLock(Heap->LockVariable, TRUE);
-Locked = TRUE;
-}
-
 /* Get pointer to the heap entry */
 HeapEntry = (PHEAP_ENTRY)Ptr - 1;
 
-/* Check this entry, fail if it's invalid */
-if (!(HeapEntry->Flags & HEAP_ENTRY_BUSY) ||
-(((ULONG_PTR)Ptr & 0x7) != 0) ||
-(HeapEntry->SegmentOffset >= HEAP_SEGMENTS))
+/* Protect with SEH in case the pointer is not valid */
+_SEH2_TRY
+{
+/* Check this entry, fail if it's invalid */
+if (!(HeapEntry->Flags & HEAP_ENTRY_BUSY) ||
+(((ULONG_PTR)Ptr & 0x7) != 0) ||
+(HeapEntry->SegmentOffset >= HEAP_SEGMENTS))
+{
+/* This is an invalid block */
+DPRINT1("HEAP: Trying to free an invalid address %p!\n", Ptr);
+
RtlSetLastWin32ErrorAndNtStatusFromNtStatus(STATUS_INVALID_PARAMETER);
+_SEH2_YIELD(return FALSE);
+}
+}
+_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
 {
-/* This is an invalid block */
+/* The pointer was invalid */
 DPRINT1("HEAP: Trying to free an invalid address %p!\n", Ptr);
 RtlSetLastWin32ErrorAndNtStatusFromNtStatus(STATUS_INVALID_PARAMETER);
+_SEH2_YIELD(return FALSE);
+}
 
-/* Release the heap lock */
-if (Locked) RtlLeaveHeapLock(Heap->LockVariable);
-return FALSE;
+/* Lock if necessary */
+if (!(Flags & HEAP_NO_SERIALIZE))
+{
+RtlEnterHeapLock(Heap->LockVariable, TRUE);
+Locked = TRUE;
 }
 
 if (HeapEntry->Flags & HEAP_ENTRY_VIRTUAL_ALLOC)