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

Order of refcount manipulation when overwriting

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 0.5.0
    • Core
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: