I want to use the git's malloc and realloc wrappers in my code for OOM(out of memory) conditions. Here is its code:
void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret) {
release_pack_memory(size, -1);
ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret)
die("Out of memory, malloc failed");
}
#ifdef XMALLOC_POISON
memset(ret, 0xA5, size);
#endif
return ret;
}
but the release_pack_memory function is in sha1_file.c header file and this function have references to the functions in other header files in Git's code and I didn't want to put so much effort for isolate this function from Git's codebase. At the moment I am looking for an alternative function for release_pack_memory function, or can you recommend me another alternative. I'll be thankful for any kind of help