lucy-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marvin Humphrey (JIRA)" <j...@apache.org>
Subject [lucy-issues] [jira] [Created] (CLOWNFISH-37) Order of refcount manipulation when overwriting
Date Thu, 23 Apr 2015 23:09:38 GMT
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)

Mime
View raw message