Menu

leakReturnValNotUsed. Return value of allocation function <...> is not stored

2015-05-29
2015-06-04
  • Teodor Todorov

    Teodor Todorov - 2015-05-29

    What to do for it to not report it or change it from error to information.
    I am using something like this:

    mypointer<int> myobject (createObj());

    where mypointeris a smart pointer and createObj returns a pointer.
    Cppcheck dedicates that myobject is a function not an obejct.

    I have tried
    <?xml version="1.0"?>
    <def>
    <function name="myobject ">
    <memory>
    <alloc>malloc</alloc>
    <dealloc>free</dealloc>
    myobject
    </memory>
    </function>
    </def>
    with no effect.

    and with rules
    but it only editing the new rule to the previous report without removing the wrong reports.

     
  • Daniel Marjamäki

    I fail to reproduce.

    Is it possible to show some example 4-5 lines of code that reproduce the problem?

    <function name="myobject ">

    this is bad configuration. myobject is not a function. don't do this.

     
  • Teodor Todorov

    Teodor Todorov - 2015-06-03

    void main()
    {
    smart_ptr<MS> s ( zaz::create() );
    }

    and it gives me "error,leakReturnValNotUsed,Return value of allocation function s is not stored."

    so i am trying to change the output because it is OK.

    but with rule-file

    <rule version="1">

    <pattern>smart_ptr<MS> s \( zaz::create\(\) \);</pattern>
    
    <message>
    
        <id>information</id>
    
        <severity>information</severity>
    
        <summary>It is not an error.</summary>
    
    </message>
    

    </rule>

    there is not a change in the output.
    I do not want to use suppression on the whole file or suppress the error on exact line.
    Just want ot change the error properties .

    And debug shows
    ,debug,debug,Unknown type 'smart_ptr<MS>'.

    May be this is not the right way to make it.

    Tried with config but:

    <def>

    <memory>
    
        <alloc>malloc</alloc>
    
        <dealloc>free</dealloc>
    
        <use>socket</use>
    
    </memory>
    

    </def>

    again with no difference in the output.

    Or my problem is within the pcre.lib and pcre.h. What to do with them to be able to use rules.

     

    Last edit: Teodor Todorov 2015-06-03
  • Teodor Todorov

    Teodor Todorov - 2015-06-04

    I tried with --library by defining smart_ptr and MS witout the other attributes. That managed the Unknown type in debug but I have no idea what to do with 's' that is detected as function - i tried to make container definition for smart_ptr because it is almost the same as the example with std::vector but result was still the same.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.