Marvin Humphrey created CLOWNFISH-37:
----------------------------------------

             Summary: Order of refcount manipulation when overwriting
                 Key: CLOWNFISH-37
                 URL: https://issues.apache.org/jira/browse/CLOWNFISH-37
             Project: Apache Lucy-Clownfish
          Issue Type: Bug
          Components: Core
            Reporter: Marvin Humphrey
            Priority: Minor
             Fix For: 0.5.0


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.

{code}
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;
}
{code}




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to