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?
Subscribe to:
Post Comments (Atom)
3 comments:
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.
Reply DeleteI am trying to improve my solution. Useful puzzle :)
any problem in the common pattern?
Reply DeleteHow about using tool like valgrind
Reply Deletevalgrind --tool=memcheck --leak-check=yes --show-reachable=yes