Fix possible double close

Signed-off-by: Sven Strickroth <email@cs-ware.de>
Merge pull request #1755 from csware/double-close

Fix possible double close