$OpenBSD$ shitty shitty shitty shitty shitty shitty. anyone with experience writing this probably would want to write an entirely new malloc for openbsd-zdoom as i have a feeling every example in the existing code (and my shitty attempts to reuse the sun stuff) would make someone vomit. i believe this is what is causing the bulk of the crashes, such as on exit, etc. typically its a memory allocation wasn't where i thought it was type error on sigsegv. --- src/m_alloc.cpp.orig Fri Dec 28 21:11:30 2012 +++ src/m_alloc.cpp Fri Dec 28 21:37:21 2012 @@ -38,6 +38,9 @@ #elif defined(__APPLE__) #include #include +#elif defined(__OpenBSD__) +#include +#include #else #include #endif @@ -52,42 +55,17 @@ #endif #if defined(__APPLE__) #define _msize(p) malloc_size(p) -#elif defined(__sun) +#elif defined(__sun) #define _msize(p) (*((size_t*)(p)-1)) +#elif defined(__OpenBSD__) +#define _msize(p) (*((size_t*)(p)-1)) #elif !defined(_WIN32) #define _msize(p) malloc_usable_size(p) // from glibc/FreeBSD #endif #ifndef _DEBUG -#if !defined(__sun) void *M_Malloc(size_t size) { - void *block = malloc(size); - - if (block == NULL) - I_FatalError("Could not malloc %zu bytes", size); - - GC::AllocBytes += _msize(block); - return block; -} - -void *M_Realloc(void *memblock, size_t size) -{ - if (memblock != NULL) - { - GC::AllocBytes -= _msize(memblock); - } - void *block = realloc(memblock, size); - if (block == NULL) - { - I_FatalError("Could not realloc %zu bytes", size); - } - GC::AllocBytes += _msize(block); - return block; -} -#else -void *M_Malloc(size_t size) -{ void *block = malloc(size+sizeof(size_t)); if (block == NULL) @@ -123,41 +101,13 @@ void *M_Realloc(void *memblock, size_t size) GC::AllocBytes += _msize(block); return block; } -#endif #else #ifdef _MSC_VER #include #endif -#if !defined(__sun) void *M_Malloc_Dbg(size_t size, const char *file, int lineno) { - void *block = _malloc_dbg(size, _NORMAL_BLOCK, file, lineno); - - if (block == NULL) - I_FatalError("Could not malloc %zu bytes", size); - - GC::AllocBytes += _msize(block); - return block; -} - -void *M_Realloc_Dbg(void *memblock, size_t size, const char *file, int lineno) -{ - if (memblock != NULL) - { - GC::AllocBytes -= _msize(memblock); - } - void *block = _realloc_dbg(memblock, size, _NORMAL_BLOCK, file, lineno); - if (block == NULL) - { - I_FatalError("Could not realloc %zu bytes", size); - } - GC::AllocBytes += _msize(block); - return block; -} -#else -void *M_Malloc_Dbg(size_t size, const char *file, int lineno) -{ void *block = _malloc_dbg(size+sizeof(size_t), _NORMAL_BLOCK, file, lineno); if (block == NULL) @@ -195,25 +145,16 @@ void *M_Realloc_Dbg(void *memblock, size_t size, const return block; } #endif -#endif -#if !defined(__sun) void M_Free (void *block) { - if (block != NULL) - { - GC::AllocBytes -= _msize(block); - free(block); - } -} -#else -void M_Free (void *block) -{ if(block != NULL) { GC::AllocBytes -= _msize(block); +#if defined(__OpenBSD__) + free(((size_t*) block)-1); +#else free(((size_t*) block)-1); +#endif } } -#endif -