UB in clangpch_cache.cpp

Discussion about CodeLite development process and patches
qdii
CodeLite Enthusiast
Posts: 13
Joined: Sun Nov 13, 2011 10:34 pm
Genuine User: Yes
IDE Question: C++
Contact:

UB in clangpch_cache.cpp

Post by qdii »

In LiteEditor/clangpch_cache.cpp

Code: Select all

void ClangTUCache::RemoveEntry(const wxString& filename)
{
    std::map<wxString, ClangCacheEntry>::iterator iter = m_cache.find(filename);
    if(iter != m_cache.end()) {
        CL_DEBUG(wxT("clang_disposeTranslationUnit for TU: %p"), (void*)iter->second.TU);
        clang_disposeTranslationUnit(iter->second.TU);
        m_cache.erase(iter);

        wxLogNull nolog;
        wxRemoveFile(iter->second.fileTU);
    }
}
When an element is found, it is deleted, which invalidates "iter", but then iter is dereferenced, which triggers an undefined behavior.
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: UB in clangpch_cache.cpp

Post by eranif »

Thanks, fixed in git head

Eran
Make sure you have read the HOW TO POST thread
Post Reply