Add custom memory replacements for malloc, realloc and free
Fixed compile errors for CentOS 6