Use rb_ensure() to free allocated objects on error