gi: support freeing returned struct