Purify revealed a potential free memory read when using std::list::remove()

StackOverflow https://stackoverflow.com/questions/23297270

  •  09-07-2023
  •  | 
  •  

Вопрос

Purify revealed a potential free memory read when using std::list::remove(). I noticed that std::list::remove() uses the type's operator== to do the comparison. However, what I have also noticed is that if the first element in the list is passed to std::list::remove(), it is deleted when it matches, but then it is still used to compare against all the other items in the list. This causes Purify to flag this as a "potential free memory read". I replaced the std::list::remove() call with erase() and an iterator, which is more efficient because it makes it loop only once versus twice in my situation.

Is there a reason std::list::remove() keeps the first element around?

Это было полезно?

Решение

This was GCC bug# 17012, fixed in 4.3.0. See also Library Working Group Defect Report 526.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top