
Fixes #62985 Fixes #58820 When 3rd-party header files are included as system headers, their overloaded `new` and `delete` operators are also considered as the std ones. However, those overloaded operator functions will also be inlined. This makes the same symbolic memory marked as released twice: during `checkPreCall` of the overloaded `delete` operator and when calling `::operator delete` after inlining the overloaded operator function (if it has). This patch attempts to fix this bug by adjusting the strategy of verifying whether the callee is a standard `new` or `delete` operator in the `isStandardNewDelete` function.
19 lines
471 B
C
19 lines
471 B
C
#ifndef OVERLOADED_DELETE_IN_HEADER
|
|
#define OVERLOADED_DELETE_IN_HEADER
|
|
|
|
struct DeleteInHeader {
|
|
int data;
|
|
static void operator delete(void *ptr);
|
|
};
|
|
|
|
void DeleteInHeader::operator delete(void *ptr) {
|
|
DeleteInHeader *self = (DeleteInHeader *)ptr;
|
|
self->data = 1; // no-warning: Still alive.
|
|
|
|
::operator delete(ptr);
|
|
|
|
self->data = 2; // expected-warning {{Use of memory after it is freed [cplusplus.NewDelete]}}
|
|
}
|
|
|
|
#endif // OVERLOADED_DELETE_IN_SYSTEM_HEADER
|