junrushao commented on PR #78:
URL: https://github.com/apache/tvm-ffi/pull/78#issuecomment-3369112623

   There's a potential leak clang-tidy detected when allocating an object in 
`include/tvm/ffi/memory.h`:
   
   <details>
   
   ```
   
/Users/jshao/Projects/tvm-ffi/tests/cpp/extra/test_structural_equal_hash.cc:154:1:
 error: Potential leak of memory pointed to by field 'data_' 
[clang-analyzer-unix.Malloc,-warnings-as-errors]
     154 | }
         | ^
   
/Users/jshao/Projects/tvm-ffi/tests/cpp/extra/test_structural_equal_hash.cc:145:55:
 note: Calling 'AccessStep::Attr'
     145 |                                                       
refl::AccessStep::Attr("body"),
         |                                                       
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/include/tvm/ffi/reflection/access_path.h:122:12: 
note: Calling constructor for 'AccessStep'
     122 |     return AccessStep(AccessKind::kAttr, std::move(field_name));
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/include/tvm/ffi/reflection/access_path.h:114:19: 
note: Calling 'make_object<tvm::ffi::reflection::AccessStepObj, 
tvm::ffi::reflection::AccessKind &, tvm::ffi::Any>'
     114 |       : ObjectRef(make_object<AccessStepObj>(kind, std::move(key))) 
{}
         |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:265:10: note: Calling 
'ObjAllocatorBase::make_object'
     265 |   return 
details::SimpleObjAllocator().make_object<T>(std::forward<Args>(args)...);
         |          
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:116:13: note: Calling 
'Handler::New'
     116 |       ptr = Handler::New(static_cast<Derived*>(this), 
std::forward<Args>(args)...);
         |             
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:179:20: note: Calling 
'AlignedAlloc<8UL>'
     179 |       void* data = AlignedAlloc<alignof(T)>(sizeof(T));
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:65:3: note: Taking 
true branch
      65 |   if constexpr (align <= alignof(std::max_align_t)) {
         |   ^
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:67:21: note: Memory 
is allocated
      67 |     if (void* ptr = std::malloc(size)) {
         |                     ^~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:67:15: note: Assuming 
'ptr' is non-null
      67 |     if (void* ptr = std::malloc(size)) {
         |               ^~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:67:5: note: Taking 
true branch
      67 |     if (void* ptr = std::malloc(size)) {
         |     ^
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:179:20: note: 
Returned allocated memory
     179 |       void* data = AlignedAlloc<alignof(T)>(sizeof(T));
         |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:116:13: note: 
Returned allocated memory
     116 |       ptr = Handler::New(static_cast<Derived*>(this), 
std::forward<Args>(args)...);
         |             
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   /Users/jshao/Projects/tvm-ffi/include/tvm/ffi/memory.h:265:10: note: 
Returned allocated memory
     265 |   return 
details::SimpleObjAllocator().make_object<T>(std::forward<Args>(args)...);
         |          
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/include/tvm/ffi/reflection/access_path.h:114:19: 
note: Returned allocated memory
     114 |       : ObjectRef(make_object<AccessStepObj>(kind, std::move(key))) 
{}
         |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/include/tvm/ffi/reflection/access_path.h:122:12: 
note: Returning from constructor for 'AccessStep'
     122 |     return AccessStep(AccessKind::kAttr, std::move(field_name));
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/tests/cpp/extra/test_structural_equal_hash.cc:145:55:
 note: Returned allocated memory
     145 |                                                       
refl::AccessStep::Attr("body"),
         |                                                       
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
/Users/jshao/Projects/tvm-ffi/tests/cpp/extra/test_structural_equal_hash.cc:154:1:
 note: Potential leak of memory pointed to by field 'data_'
     154 | }
         | ^
   ```
   
   </details>
   
   Example code that triggers this warning:
   
   ```C++
   Array<refl::AccessStep> steps = {refl::AccessStep::Attr("body")};
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to