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

Code before:
        HeapList* Heap;
        void* MapBase;
        void* HdrMap;
        size_t MaxCodeHeapSize;
    };

    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;
            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 doesn't handle self-assignment correctly. If this == &other, the code will set m_manager to NULL and then return, potentially leaking the resource. You should add a self-assignment check at the beginning of the function.

Code after:
        HeapList* Heap;
        void* MapBase;
        void* HdrMap;
        size_t MaxCodeHeapSize;
    };

    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();