Use valgrind to find memory leaks
Last test doesn't show any memory leaks. :)
I used valgrind on my updated code .Its showing memory leaks.If I can help in fixing them any way please guide me.
==5040== in use at exit: 1,820,478 bytes in 21,635 blocks
==5040== total heap usage: 219,347 allocs, 197,712 frees, 56,571,499 bytes allocated
==5040== LEAK SUMMARY:
==5040== definitely lost: 3,240 bytes in 18 blocks
==5040== indirectly lost: 27,002 bytes in 762 blocks
==5040== possibly lost: 40,061 bytes in 585 blocks
==5040== still reachable: 1,574,703 bytes in 19,391 blocks
==5040== suppressed: 0 bytes in 0 blocks
Yes, you can try to fix memory leaks. We will help you if you'll show us code that leaks.