Random commentary about Machine Learning, BigData, Spark, Deep Learning, C++, STL, Boost, Perl, Python, Algorithms, Problem Solving and Web Search
Sunday, February 21, 2010
Malloc and Free
A certain program makes use of malloc and free several times. Anyway, you forgot to free one block of memory allocated with one malloc. What strategy do you use to check the place where the unpaired malloc is located?
If I have pointed all the free'd pointers to NULL and I know the name of all the pointers (say, I had declared them at the beginning of the program) then I would just check which one of them doesn't point to NULL.
I am trying to improve my solution. Useful puzzle :)
If I have pointed all the free'd pointers to NULL and I know the name of all the pointers (say, I had declared them at the beginning of the program) then I would just check which one of them doesn't point to NULL.
ReplyDeleteI am trying to improve my solution. Useful puzzle :)
any problem in the common pattern?
ReplyDeleteHow about using tool like valgrind
ReplyDeletevalgrind --tool=memcheck --leak-check=yes --show-reachable=yes