Repository: dotnet/runtime
File: src/coreclr/vm/codeman.h (C/C++)

Code before:
    };

    class EECodeGenManagerReleaseIteratorHolder
    {
        EECodeGenManager* m_manager;
    public:
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManager* manager);
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManagerReleaseIteratorHolder const&) = delete;
        EECodeGenManagerReleaseIteratorHolder& operator=(EECodeGenManagerReleaseIteratorHolder const&) = delete;
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManagerReleaseIteratorHolder&& other)
        {
            LIMITED_METHOD_CONTRACT;
            m_manager = other.m_manager;
            other.m_manager = NULL;
        }
        EECodeGenManagerReleaseIteratorHolder& operator=(EECodeGenManagerReleaseIteratorHolder&& other)
        {
            LIMITED_METHOD_CONTRACT;

            if (this != &other)
            {
                m_manager = other.m_manager;
                other.m_manager = NULL;
            }
            return *this;
        }
        ~EECodeGenManagerReleaseIteratorHolder();
    };

    EECodeGenManagerReleaseIteratorHolder m_manager;
    MethodSectionIterator m_Iterator;
    CUnorderedArray<HeapListState, 64> m_Heaps;
    int32_t m_HeapsIndexNext;
    LoaderAllocator* m_pLoaderAllocatorFilter;
    MethodDesc* m_pCurrent;
    DWORD m_codeType;

public:
    CodeHeapIterator(EECodeGenManager* manager, HeapList* heapList, LoaderAllocator* pLoaderAllocatorFilter);

    CodeHeapIterator(CodeHeapIterator const&) = delete;
    CodeHeapIterator& operator=(CodeHeapIterator const&) = delete;
    CodeHeapIterator(CodeHeapIterator&&) = default;
    CodeHeapIterator& operator=(CodeHeapIterator&&) = default;

    bool Next();

    MethodDesc* GetMethod()
    {
        LIMITED_METHOD_CONTRACT;
        return m_pCurrent;

Review comment (suggestion):
The move assignment operator should release the currently held manager before taking ownership of the new one. Without this, if the holder already owns a manager, it will be leaked when reassigned. Consider calling the destructor logic (ReleaseIterator) on the current m_manager before assigning from other.

Code after:
    };

    class EECodeGenManagerReleaseIteratorHolder
    {
        EECodeGenManager* m_manager;
    public:
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManager* manager);
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManagerReleaseIteratorHolder const&) = delete;
        EECodeGenManagerReleaseIteratorHolder& operator=(EECodeGenManagerReleaseIteratorHolder const&) = delete;
        EECodeGenManagerReleaseIteratorHolder(EECodeGenManagerReleaseIteratorHolder&& other)
        {
            LIMITED_METHOD_CONTRACT;
            m_manager = other.m_manager;
            other.m_manager = NULL;
        }
        EECodeGenManagerReleaseIteratorHolder& operator=(EECodeGenManagerReleaseIteratorHolder&& other);
        ~EECodeGenManagerReleaseIteratorHolder();
    };

    EECodeGenManagerReleaseIteratorHolder m_manager;
    MethodSectionIterator m_Iterator;
    CUnorderedArray<HeapListState, 64> m_Heaps;
    int32_t m_HeapsIndexNext;
    LoaderAllocator* m_pLoaderAllocatorFilter;
    MethodDesc* m_pCurrent;
    DWORD m_codeType;

public:
    CodeHeapIterator(EECodeGenManager* manager, HeapList* heapList, LoaderAllocator* pLoaderAllocatorFilter);

    CodeHeapIterator(CodeHeapIterator const&) = delete;
    CodeHeapIterator& operator=(CodeHeapIterator const&) = delete;
    CodeHeapIterator(CodeHeapIterator&&) = default;
    CodeHeapIterator& operator=(CodeHeapIterator&&) = default;

    bool Next();

    MethodDesc* GetMethod()
    {
        LIMITED_METHOD_CONTRACT;
        return m_pCurrent;
    }

    TADDR GetMethodCode()
    {
        LIMITED_METHOD_CONTRACT;
        return (TADDR)m_Iterator.GetMethodCode();
    }

private:
    bool NextMethodSectionIterator();