Page 1 of 1

UB in clangpch_cache.cpp

Posted: Mon Sep 30, 2013 2:05 am
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.

Re: UB in clangpch_cache.cpp

Posted: Mon Sep 30, 2013 8:01 am
by eranif
Thanks, fixed in git head

Eran