Hello Friends,

I have a huge program having multiple malloc & free. At the end of my program, I wish to print the memory leak which has occured.

There are obviously many solutions to this problem.
e.g. Simplest one:
1) When you allocate the memory, keep the allocated memory pointer in a linked list, and remove it once the memory is freed. In the end, traverse through the list and print the left over pointers(which means leaks).

Can you suggest a better solution?

Regards,
Vivek

A suitable build with Visual Studio for example would produce that list for you.

A suitable build with Visual Studio for example would produce that list for you.

Let's say I am using Turbo C compiler in Windows. So, my logic and program should be able to find it. As one solution i suggested in my original post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.