ok. show us more code, please.
(Have you tried a debugger to check the crash is related to that close() call?)