[PATCH][Review request] unix.Malloc checker improvement: +handling new/delete, +memory.MismatchedFree, +memory.MismatchedDelete, +improved display names for allocators/deallocators

Anton Yartsev anton.yartsev at gmail.com
Thu Apr 4 18:59:30 PDT 2013


>>>>>
>>>>> ---
>>>>> +  // Check if an expected deallocation function matches the real one.
>>>>> +  if (RsBase &&
>>>>> +  RsBase->getAllocationFamily() != AF_None &&
>>>>> +  RsBase->getAllocationFamily() != getAllocationFamily(C, 
>>>>> ParentExpr) ) {
>>>>> Is it possible to have AF_None family here? Shouldn't " 
>>>>> RsBase->getAllocationFamily() != AF_None" be inside an assert?
>>>> It is possible. In the example below 
>>>> initWithCharactersNoCopy:length:freeWhenDone takes ownership of 
>>>> memory allocated by unknown means, RefState with AF_None is bound 
>>>> to the call and after, when free() is processed, we have 
>>>> RsBase->getAllocationFamily() == AF_None.
>>>
>>> My understanding is that this API assumes that the memory belongs to 
>>> the malloc family. So, for example, we would warn on freeing with a 
>>> regular "free" after freeing with "initWithCharactersNoCopy.. 
>>> freeWhenDone".
>>>
>>> If the family is unknown, we should not be tracking the memory at all.
>> Great idea, I'll include corresponding changes in the next patch 
>> devoted to unix.MismatchedDeallocator

I am sitting on the patch that disables tracking if unknown memory by 
checkPostObjCMessage().
The only thing preventing me from committing is the presence of the 
following testcase in malloc.mm:

void test12365078_nocheck_nomalloc(unichar *characters) {
   NSString *string = [[NSString alloc] 
initWithCharactersNoCopy:characters length:12 freeWhenDone:1];
   free(characters); // expected-warning {{Attempt to free non-owned 
memory}}
}

Should this warning be muted?

-- 
Anton

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130405/b274c514/attachment.html>


More information about the cfe-commits mailing list