re: I'm an Expert in Memory Management & Segfaults, Ask Me Anything! VIEW POST

re: What are some of the common issues you find when working in memory management? Do you have one way of working through them or multiple?

I do go through a little list in my mind:

  • Do my allocations and frees match? (malloc and its cousins with free, new with delete, new[] with delete[]).
  • Do I null out my pointers immediately after freeing?
  • Do I check if a pointer is null before using it?
  • Does my pointer math have any edge cases?
  • Are my iteration loops all safe? (I always get uneasy around while loops that touch allocated memory.)
  • Do my recursive functions have explicit stop conditions?
  • Are my C-strings (if any) null terminated?
  • Are my destructors properly freeing allocated memory?
  • Do I have tests for all major functionalities?
  • Are all my tests running Valgrind-pure?
code of conduct - report abuse