char *xstrdup(const char *str) { char *ret = strdup(str); if (!ret) { release_pack_memory(strlen(str) + 1, -1); ret = strdup(str); if (!ret) die("Out of memory, strdup failed"); } return ret; }
char *xstrdup(const char *str) { char *ret = strdup(str); if (!ret) { #if GIT_ENCWRAPPER_CUTOFF release_pack_memory(strlen(str) + 1, -1); ret = strdup(str); if (!ret) #endif die("Out of memory, strdup failed"); } return ret; }
void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { void *ret = mmap(start, length, prot, flags, fd, offset); if (ret == MAP_FAILED) { if (!length) return NULL; release_pack_memory(length, fd); ret = mmap(start, length, prot, flags, fd, offset); if (ret == MAP_FAILED) die("Out of memory? mmap failed: %s", strerror(errno)); } return ret; }
void *xcalloc(size_t nmemb, size_t size) { void *ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) { release_pack_memory(nmemb * size, -1); ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) die("Out of memory, calloc failed"); } return ret; }
void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { release_pack_memory(size, -1); ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) die("Out of memory, realloc failed"); } return ret; }
void *xcalloc(size_t nmemb, size_t size) { void *ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) { #if GIT_ENCWRAPPER_CUTOFF release_pack_memory(nmemb * size, -1); ret = calloc(nmemb, size); if (!ret && (!nmemb || !size)) ret = calloc(1, 1); if (!ret) #endif die("Out of memory, calloc failed"); } return ret; }
void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) { #if GIT_ENCWRAPPER_CUTOFF release_pack_memory(size, -1); ret = realloc(ptr, size); if (!ret && !size) ret = realloc(ptr, 1); if (!ret) #endif die("Out of memory, realloc failed"); } return ret; }
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; }
static void try_to_free_builtin(size_t size) { release_pack_memory(size, -1); }