I have an application which I use to catch any segmentation fault or ctrl-c. Using the below code, I am able to catch the segmentation fault but the handler is being called
Well you could set a state variable and only free memory if its not set. The signal handler will be called everytime, you can't control that AFAIK.