]> granicus.if.org Git - clang/commitdiff
Fix pr6293. If ptr is NULL, no operation is preformed.
authorZhongxing Xu <xuzhongxing@gmail.com>
Sun, 14 Feb 2010 06:49:48 +0000 (06:49 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Sun, 14 Feb 2010 06:49:48 +0000 (06:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96154 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/MallocChecker.cpp
test/Analysis/malloc.c

index 3be2e0299bba881a20c31faca735b0257008be95..4ff98642e1c278a529489c08b97ff59b30dc7a60 100644 (file)
@@ -172,6 +172,11 @@ void MallocChecker::FreeMem(CheckerContext &C, const CallExpr *CE) {
 const GRState *MallocChecker::FreeMemAux(CheckerContext &C, const CallExpr *CE,
                                          const GRState *state) {
   SVal ArgVal = state->getSVal(CE->getArg(0));
+
+  // If ptr is NULL, no operation is preformed.
+  if (ArgVal.isZeroConstant())
+    return state;
+
   SymbolRef Sym = ArgVal.getAsLocSymbol();
   assert(Sym);
 
index 518ab82ff11f943f56a9117c53c8364392b0aeb0..3cce1b0d2ef4c5be3097b3a30bf873c09e2d7de4 100644 (file)
@@ -57,3 +57,7 @@ void pr6069() {
   char *buf = doit2();
   free(buf);
 }
+
+void pr6293() {
+  free(0);
+}