Skip to content

Commit

Permalink
ren MALLOC to malloc, fix malloc overflow on large sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 31, 2020
1 parent c7638f7 commit 1ba0e41
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/HEAP32/MALLOC.C

This file was deleted.

41 changes: 41 additions & 0 deletions src/HEAP32/malloc.c
@@ -0,0 +1,41 @@
/* Copyright (C) 1986-1994 by Digital Mars. $Revision: 1.1.1.1 $ */

#include <stdlib.h>
#include "semlock.h"
#include "multpool.h"

#if __cplusplus
extern "C" {
#endif

void *malloc (size_t m_size)
{
#if USEHEAP
/* The +2 is because there's a buffer overflow somewhere in stlport.
* It is triggered by stltutorial\ex13-01.cpp
*/
#if _WIN32
/* Set a max size because of access violations in Win32 Heap functions.
* Size is determined experimentally.
*/
if (m_size < 0xD5550000)
return HeapAlloc(_default_heap, 0, m_size + 2);
return NULL;
#else
return HeapAlloc(_default_heap, 0, m_size + 2);
#endif
#else
void *p;

LockSemaphore(_semAlloc);
p = RTLMultiPool::GetMainHeap()->Alloc(m_size);
UnlockSemaphore(_semAlloc);

return p;
#endif
}

#if __cplusplus
}
#endif

0 comments on commit 1ba0e41

Please sign in to comment.