wrapper.c 609 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Various trivial helper wrappers around standard functions
  3. */
  4. #include "cache.h"
  5. /*
  6. * There's no pack memory to release - but stay close to the Git
  7. * version so wrap this away:
  8. */
  9. static inline void release_pack_memory(size_t size __maybe_unused,
  10. int flag __maybe_unused)
  11. {
  12. }
  13. void *xrealloc(void *ptr, size_t size)
  14. {
  15. void *ret = realloc(ptr, size);
  16. if (!ret && !size)
  17. ret = realloc(ptr, 1);
  18. if (!ret) {
  19. release_pack_memory(size, -1);
  20. ret = realloc(ptr, size);
  21. if (!ret && !size)
  22. ret = realloc(ptr, 1);
  23. if (!ret)
  24. die("Out of memory, realloc failed");
  25. }
  26. return ret;
  27. }