Fix double free()

Fixes #2070