Ignore:
Timestamp:
Jul 7, 2010, 9:07:29 AM (15 years ago)
Author:
Darin Adler
Message:

Make clear set the pointer to 0 before deletion
https://bugs.webkit.org/show_bug.cgi?id=41727

Reviewed by Adam Barth.

  • wtf/OwnArrayPtr.h: Changed code so we always set the pointer to its new

value before deleting the old one, including in the set function and the
clear function. This required changing safeDelete.

  • wtf/OwnPtr.h: Ditto. Also removed some extra null checks.
  • wtf/PassOwnPtr.h: Ditto.
  • wtf/PassRefPtr.h: Changed code so we always set the pointer to its new

value before deref'ing the old one in the clear function. Also added a
leakRef function for NonNullPassRefPtr.

  • wtf/RefPtr.h: Ditto.
  • wtf/gobject/GOwnPtr.h: More of the same.
  • wtf/gobject/GRefPtr.h: Ditto.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/PassRefPtr.h

    r62213 r62674  
    7777        T* get() const { return m_ptr; }
    7878
    79         void clear() { T* ptr = m_ptr; derefIfNotNull(ptr); m_ptr = 0; }
     79        void clear();
    8080        T* leakRef() const;
    8181
     
    152152        T* get() const { return m_ptr; }
    153153
    154         void clear() { derefIfNotNull(m_ptr); m_ptr = 0; }
    155         T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; }
     154        void clear();
     155        T* leakRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; }
    156156
    157157        T& operator*() const { return *m_ptr; }
    158158        T* operator->() const { return m_ptr; }
     159
     160        // FIXME: Remove releaseRef once we change all callers to call leakRef instead.
     161        T* releaseRef() const { return leakRef(); }
    159162
    160163    private:
     
    169172    }
    170173
     174    template<typename T> inline void PassRefPtr<T>::clear()
     175    {
     176        T* ptr = m_ptr;
     177        m_ptr = 0;
     178        derefIfNotNull(ptr);
     179    }
     180
    171181    template<typename T> inline T* PassRefPtr<T>::leakRef() const
    172182    {
     
    280290    {
    281291        return p.get();
     292    }
     293
     294    template<typename T> inline void NonNullPassRefPtr<T>::clear()
     295    {
     296        T* ptr = m_ptr;
     297        m_ptr = 0;
     298        derefIfNotNull(ptr);
    282299    }
    283300
Note: See TracChangeset for help on using the changeset viewer.