Avoid assert and crash when allocating smaller large objects in sgen.
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 5 Dec 2011 14:44:51 +0000 (15:44 +0100)
committerPaolo Molaro <lupus@oddwiz.org>
Mon, 5 Dec 2011 14:44:51 +0000 (15:44 +0100)
mono/metadata/sgen-los.c
mono/utils/mono-mmap.c

index 3e0b0bbacdecb527b3127bd26b11fed508b1341d..67266ae0e6669b4e2fe1719c04c0419006973ad0 100644 (file)
@@ -246,6 +246,9 @@ get_los_section_memory (size_t size)
 
        section = mono_sgen_alloc_os_memory_aligned (LOS_SECTION_SIZE, LOS_SECTION_SIZE, TRUE);
 
+       if (!section)
+               return NULL;
+
        free_chunks = (LOSFreeChunks*)((char*)section + LOS_CHUNK_SIZE);
        free_chunks->size = LOS_SECTION_SIZE - LOS_CHUNK_SIZE;
        free_chunks->next_size = los_fast_free_lists [0];
index 0b3aa083da7ee70b3578d16e4434b60f88a6eac8..b69fa2ac4370e7ae778ecd788d8def198bcb85a3 100644 (file)
@@ -122,7 +122,8 @@ mono_valloc_aligned (size_t length, size_t alignment, int flags)
        char *mem = VirtualAlloc (NULL, length + alignment, MEM_RESERVE, prot);
        char *aligned;
 
-       g_assert (mem);
+       if (!mem)
+               return NULL;
 
        aligned = aligned_address (mem, length, alignment);
 
@@ -662,7 +663,8 @@ mono_valloc_aligned (size_t size, size_t alignment, int flags)
        char *mem = mono_valloc (NULL, size + alignment, flags);
        char *aligned;
 
-       g_assert (mem);
+       if (!mem)
+               return NULL;
 
        aligned = aligned_address (mem, size, alignment);