Hello special_20,
as far as I remember this subroutine was specifically created for the DAMP project to mimic the role of an API before the release of the MASCARET one. If you are a user of DAMP, you may consider to use a version based on the official MASCARET API if it is available.
If it is not available or you cannot change of version, try to compile and run your executable in debug mode in order to identify the deallocation problem. As all pointers are tested for association before the deallocation, you can also try to force the initialisation for all the pointers to a null value. This will avoid the use of uninitialised pointers.
Regards