That function should call the release method of the automation object that the handles belonged to, and I would suspect that is where the lock up comes from.
I have seen similar things happen and the best way to describe is is below(it might not actually do it, but it should show you what I mean).
Lets say you open up Word, create a file and then close the handle to the 'Word' Handle. Word will often ask you if you want to save the created file, which hangs up the closing of the handle until you physically go and do the saving yourself. (Note, 99% of the time, it would probably just shut down but this is an example). Without knowing what your automation object is, I can only guess...
Regards
Chris