clib/gir: fix ownership for casting. Only take ownership after we get the final ctypes instance, otherwise the old one unrefs before we use the new one.