Fix segfault with duplicate handles. Issue #2267
Merge pull request #405 from baptr/issue-2267

Fix segfault with duplicate handles. Issue #2267