allocating and freeing input correctly