summaryrefslogtreecommitdiff
path: root/test/Analysis/malloc-free-after-return.cpp
blob: cebd79a1a15e034f6710d7f2bfe6668befb6b6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete -verify %s

#include "Inputs/system-header-simulator-cxx.h"

struct S {
  S() : Data(new int) {}
  ~S() { delete Data; }
  int *getData() { return Data; }

private:
  int *Data;
};

int *freeAfterReturnTemp() {
  return S().getData(); // expected-warning {{Use of memory after it is freed}}
}

int *freeAfterReturnLocal() {
  S X;
  return X.getData(); // expected-warning {{Use of memory after it is freed}}
}