diff --git a/memory/heap.c b/memory/heap.c
index 3ba70eb7e29386509c2133adf38f204eb397cfe9..3210422ddf0f2ad60d39ef234c206ae938838911 100644
--- a/memory/heap.c
+++ b/memory/heap.c
@@ -908,7 +908,7 @@ void WINAPI UnMapLS( SEGPTR sptr )
     /* check if ptr is inside segptr heap */
     EnterCriticalSection( &segptrHeap->critSection );
     subheap = HEAP_FindSubHeap( segptrHeap, PTR_SEG_TO_LIN(sptr) );
-    if (subheap->selector != SELECTOROF(sptr)) subheap = NULL;
+    if ((subheap) && (subheap->selector != SELECTOROF(sptr))) subheap = NULL;
     LeaveCriticalSection( &segptrHeap->critSection );
     /* if not inside heap, free the selector */
     if (!subheap) FreeSelector16( SELECTOROF(sptr) );