File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79 Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1111| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
1212| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1313| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |
14+ | PlacementNew.cpp:36:3:36:36 | ... = ... | Resource p1 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
15+ | PlacementNew.cpp:37:3:37:51 | ... = ... | Resource p2 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
16+ | PlacementNew.cpp:38:3:38:49 | ... = ... | Resource p3 is acquired by class MyTestForPlacementNew but not released anywhere in this class. |
1417| SelfRegistering.cpp:25:3:25:24 | ... = ... | Resource side is acquired by class MyOwner but not released anywhere in this class. |
1518| Variants.cpp:23:3:23:13 | ... = ... | Resource f is acquired by class MyClass4 but not released anywhere in this class. |
Original file line number Diff line number Diff line change 1+
2+ typedef unsigned long size_t ;
3+
4+ namespace std
5+ {
6+ using ::size_t ;
7+ struct nothrow_t {};
8+ extern const nothrow_t nothrow;
9+ }
10+
11+ // nothrow new
12+ void * operator new (std::size_t size, const std::nothrow_t &) throw ();
13+
14+ // placement new
15+ void * operator new (std::size_t size, void * ptr) throw ();
16+
17+ // ---
18+
19+ class MyClassForPlacementNew
20+ {
21+ public:
22+ MyClassForPlacementNew (int _v) : v(_v) {}
23+ ~MyClassForPlacementNew () {}
24+
25+ private:
26+ int v;
27+ };
28+
29+ class MyTestForPlacementNew
30+ {
31+ public:
32+ MyTestForPlacementNew ()
33+ {
34+ void *buffer_ptr = buffer;
35+
36+ p1 = new MyClassForPlacementNew (1 ); // BAD: not released
37+ p2 = new (std::nothrow) MyClassForPlacementNew (2 ); // BAD: not released
38+ p3 = new (buffer_ptr) MyClassForPlacementNew (3 ); // GOOD: placement new, not an allocation [FALSE POSITIVE]
39+ }
40+
41+ ~MyTestForPlacementNew ()
42+ {
43+ }
44+
45+ MyClassForPlacementNew *p1, *p2, *p3;
46+ char buffer[sizeof (MyClassForPlacementNew)];
47+ };
You can’t perform that action at this time.
0 commit comments