Tips and Tricks to avoid memory leaks in writing C
When I write C I used to prototype the model first, then fix the memory leaks. I think its OK for throw code. I find that these leaks are mostly due to patterns of code that one avoids.
Like,
1. not assigning null to a pointer after freeing it
2. not allocating enough memory for string processing
Please throw in your tips and tricks to avoid memory leaks and memory related problems.
4 comments
[ 3.1 ms ] story [ 19.0 ms ] thread#define memalloc(x,y) { x=0;if(x=malloc(y)){}else{printf("error:no mem");} }