fix some crashes in the perl bindings