Replace malloc.h by stdlib.h

On true unices malloc.h was never available and on Linux one should
include stdlib.h instead. While this change is necessary to build
rbdoom3 on FreeBSD and other true unices, the big question is what
it means to Windows.
Add FreeBSD defines
Include stddef.h for ptrdiff_t on FreeBSD
Add an explicit cast to shut up g++47 on FreeBSD
There's no libdl on FreeBSD