Fix an issue that it segfault on close

Issue: #2
Merge branch 'Issue2_SegFaultOnClose'