[cfe-commits] r99058 - /cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h
Ted Kremenek
kremenek at apple.com
Sat Mar 20 08:45:06 PDT 2010
Author: kremenek
Date: Sat Mar 20 10:45:06 2010
New Revision: 99058
URL: http://llvm.org/viewvc/llvm-project?rev=99058&view=rev
Log:
Fix use-of-invalid-memory found by Valgrind and Windows buildbots.
We were inserting a value into a std::vector<> while iterating over
it, which could cause the underlying memory to get deallocated
and reallocated. While not the best solution, use an llvm::ImmutableList
for now as it is safely supports insertions during iteration.
Modified:
cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h
Modified: cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h?rev=99058&r1=99057&r2=99058&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h (original)
+++ cfe/trunk/include/clang/Checker/BugReporter/BugReporter.h Sat Mar 20 10:45:06 2010
@@ -24,6 +24,7 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/ImmutableSet.h"
+#include "llvm/ADT/ImmutableList.h"
#include <list>
namespace clang {
@@ -385,16 +386,19 @@
class BugReporterContext {
GRBugReporter &BR;
- std::vector<BugReporterVisitor*> Callbacks;
+ // Not the most efficient data structure, but we use an ImmutableList for the
+ // Callbacks because it is safe to make additions to list during iteration.
+ llvm::ImmutableList<BugReporterVisitor*>::Factory F;
+ llvm::ImmutableList<BugReporterVisitor*> Callbacks;
public:
- BugReporterContext(GRBugReporter& br) : BR(br) {}
+ BugReporterContext(GRBugReporter& br) : BR(br), Callbacks(F.GetEmptyList()) {}
virtual ~BugReporterContext();
void addVisitor(BugReporterVisitor* visitor) {
- if (visitor) Callbacks.push_back(visitor);
+ if (visitor) Callbacks = F.Add(visitor, Callbacks);
}
- typedef std::vector<BugReporterVisitor*>::iterator visitor_iterator;
+ typedef llvm::ImmutableList<BugReporterVisitor*>::iterator visitor_iterator;
visitor_iterator visitor_begin() { return Callbacks.begin(); }
visitor_iterator visitor_end() { return Callbacks.end(); }
More information about the cfe-commits
mailing list