You did not tell anything about your system, as for example the programming language, but in general a well wrote code has a debug mode selection, which is a variable or preprocessor that once enabled, makes the code logging either at console or to a text file (or even via UART), a lot of information about where it is at each pass, as well as showing value of critical variables. This way you can check what the last event recordered and than try to increase the level of detailing of the debug in the last passed routine; that is, it is an experiment of trial and error, converging to the exact point where some allocated memory has certainly not been released.