Uploaded image for project: 'Apache Lucy-Clownfish'
  1. Apache Lucy-Clownfish
  2. CLOWNFISH-37

Order of refcount manipulation when overwriting

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.5.0
    • Component/s: Core
    • Labels:
      None

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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              marvin Marvin Humphrey
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: