Skip to content

Commit b4d62d5

Browse files
authored
【Hackathon 6th Fundable Projects 2 No.12】clang-analyzer-cplusplus.NewDeleteLeaks-final (#64600)
* 5.26 * 5.26 * 5.26 * 5.26 * 5.26 * 5.26 * 5.26 * 5.26 * 5.26
1 parent b1163e6 commit b4d62d5

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

.clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ clang-analyzer-core.uninitialized.Assign,
7070
clang-analyzer-cplusplus.InnerPointer,
7171
-clang-analyzer-cplusplus.Move,
7272
-clang-analyzer-cplusplus.NewDelete,
73-
-clang-analyzer-cplusplus.NewDeleteLeaks,
73+
clang-analyzer-cplusplus.NewDeleteLeaks,
7474
-clang-analyzer-cplusplus.PureVirtualCall,
7575
-clang-analyzer-cplusplus.SelfAssignment,
7676
-clang-analyzer-cplusplus.SmartPtr,

paddle/fluid/platform/enforce_test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ TEST(enforce, cannot_to_string_type) {
596596
TEST(GET_DATA_SAFELY_MACRO, SUCCESS) {
597597
int* a = new int(10); // NOLINT
598598
GET_DATA_SAFELY(a, "Input", "X", "dummy");
599+
delete a;
599600
}
600601

601602
TEST(GET_DATA_SAFELY_MACRO, FAIL) {

paddle/pir/src/core/op_info_impl.cc

+23-17
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,34 @@ OpInfo OpInfoImpl::Create(Dialect *dialect,
7272
<< " interfaces, " << traits_num << " traits, " << attributes_num
7373
<< " attributes.";
7474
size_t base_size = sizeof(TypeId) * traits_num + sizeof(OpInfoImpl);
75-
char *base_ptr = static_cast<char *>(::operator new(base_size));
75+
std::unique_ptr<char[]> base_ptr(new char[base_size]);
7676
VLOG(10) << "Malloc " << base_size << " Bytes at "
77-
<< static_cast<void *>(base_ptr);
77+
<< static_cast<void *>(base_ptr.get());
78+
79+
char *raw_base_ptr = base_ptr.get();
7880
if (traits_num > 0) {
79-
auto p_first_trait = reinterpret_cast<TypeId *>(base_ptr);
80-
memcpy(base_ptr, trait_set.data(), sizeof(TypeId) * traits_num);
81+
auto p_first_trait = reinterpret_cast<TypeId *>(raw_base_ptr);
82+
memcpy(raw_base_ptr, trait_set.data(), sizeof(TypeId) * traits_num);
8183
std::sort(p_first_trait, p_first_trait + traits_num);
82-
base_ptr += traits_num * sizeof(TypeId);
84+
raw_base_ptr += traits_num * sizeof(TypeId);
8385
}
86+
8487
// Construct OpInfoImpl.
85-
VLOG(10) << "Construct OpInfoImpl at " << reinterpret_cast<void *>(base_ptr)
86-
<< " ......";
87-
OpInfo op_info = OpInfo(new (base_ptr) OpInfoImpl(std::move(interface_set),
88-
dialect,
89-
op_id,
90-
op_name,
91-
traits_num,
92-
attributes_num,
93-
attributes_name,
94-
verify_sig,
95-
verify_region));
96-
return op_info;
88+
VLOG(10) << "Construct OpInfoImpl at "
89+
<< reinterpret_cast<void *>(raw_base_ptr) << " ......";
90+
OpInfoImpl *impl = new (raw_base_ptr) OpInfoImpl(std::move(interface_set),
91+
dialect,
92+
op_id,
93+
op_name,
94+
traits_num,
95+
attributes_num,
96+
attributes_name,
97+
verify_sig,
98+
verify_region);
99+
100+
// Release the unique_ptr ownership after successful construction
101+
base_ptr.release();
102+
return OpInfo(impl);
97103
}
98104
void OpInfoImpl::Destroy(OpInfo info) {
99105
if (info.impl_) {

0 commit comments

Comments
 (0)