[perl #42648] [PATCH] crash in win32/VMem.h when out of memory
Devin Heitmueller [Fri, 20 Apr 2007 14:49:08 +0000 (07:49 -0700)]
From: "Devin Heitmueller" (via RT) <perlbug-followup@perl.org>
Message-ID: <rt-3.6.HEAD-30201-1177105747-239.42648-75-0@perl.org>

p4raw-id: //depot/perl@31054

win32/vmem.h

index 25f2376..460f557 100644 (file)
@@ -164,6 +164,10 @@ void* VMem::Malloc(size_t size)
 #ifdef _USE_LINKED_LIST
     GetLock();
     PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)m_pmalloc(size+sizeof(MEMORY_BLOCK_HEADER));
+    if (!ptr) {
+       FreeLock();
+       return NULL;
+    }
     LinkBlock(ptr);
     FreeLock();
     return (ptr+1);
@@ -187,6 +191,10 @@ void* VMem::Realloc(void* pMem, size_t size)
     PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)(((char*)pMem)-sizeof(MEMORY_BLOCK_HEADER));
     UnlinkBlock(ptr);
     ptr = (PMEMORY_BLOCK_HEADER)m_prealloc(ptr, size+sizeof(MEMORY_BLOCK_HEADER));
+    if (!ptr) {
+       FreeLock();
+       return NULL;
+    }
     LinkBlock(ptr);
     FreeLock();