alloc.c 895 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include <sys/mman.h>
  7. #ifdef L_calloc_dbg
  8. void *calloc_dbg(size_t num, size_t size, char *function, char *file,
  9. int line)
  10. {
  11. void *ptr;
  12. fprintf(stderr, "calloc of %ld bytes at %s @%s:%d = ",
  13. (long) (num * size), function, file, line);
  14. ptr = calloc(num, size);
  15. fprintf(stderr, "%p\n", ptr);
  16. return ptr;
  17. }
  18. #endif
  19. #ifdef L_malloc_dbg
  20. void *malloc_dbg(size_t len, char *function, char *file, int line)
  21. {
  22. void *result;
  23. fprintf(stderr, "malloc of %ld bytes at %s @%s:%d = ", (long) len,
  24. function, file, line);
  25. result = malloc(len);
  26. fprintf(stderr, "%p\n", result);
  27. return result;
  28. }
  29. #endif
  30. #ifdef L_free_dbg
  31. void free_dbg(void *ptr, char *function, char *file, int line)
  32. {
  33. fprintf(stderr, "free of %p at %s @%s:%d\n", ptr, function, file,
  34. line);
  35. free(ptr);
  36. }
  37. #endif