Description
There are a number of places in Clownfish where we decref a member variable then overwrite it with an incref'd argument. This can cause problem if for example a value overwrites itself, because the decref can cause the refcount to fall to 0.
We should instead first capture the incref to a temp variable, then decref, then overwrite.
void Foo_Set_Thing_IMP(Foo *self, Obj *thing) { - DECREF(self->thing); - self->thing = INCREF(thing); + Obj *temp = INCREF(thing); + DECREF(self->thing); + self->thing = temp; }