××.c:1562]: (error) Memory leak: new_context at "return 0" code line which is the end of the function.
So I have to add "// cppcheck-suppress memleak" before "return 0;" to spress the error.
However, I notice if developer write another memleak, cppcheck will ignore it.
Is there another method to imrove this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We malloc a memory block and add it to a list in one function and release it in another function. So we do not think this need be fixed. However, we just want to suppress it. Any idea?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
We malloc a memory block and add it to a list in one function and release it in another function.
If you don't have a real leak then Cppcheck should not warn. So, I would like to fix Cppcheck so it does not warn.
There is probably some detail in your code that makes Cppcheck confused.
Can you please show a minimal code example that reproduce such wrong warning. I recommend that you take your real code then remove #includes and functions that are not directly related to this leak.. and then recheck the file to see that Cppcheck still shows the warning. If warning is not shown then some #include or function you removed IS somehow related. Then maybe you can try to remove unrelated statements etc.
Then a ticket should be reported in our issue tracker (http://trac.cppcheck.net) so we can fix the problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
cppcheck report below error
××.c:1562]: (error) Memory leak: new_context at "return 0" code line which is the end of the function.
So I have to add "// cppcheck-suppress memleak" before "return 0;" to spress the error.
However, I notice if developer write another memleak, cppcheck will ignore it.
Is there another method to imrove this?
why do you suppress it? is the warning wrong? if the warning is wrong please report a ticket so we can fix it.
We malloc a memory block and add it to a list in one function and release it in another function. So we do not think this need be fixed. However, we just want to suppress it. Any idea?
If you don't have a real leak then Cppcheck should not warn. So, I would like to fix Cppcheck so it does not warn.
There is probably some detail in your code that makes Cppcheck confused.
Can you please show a minimal code example that reproduce such wrong warning. I recommend that you take your real code then remove #includes and functions that are not directly related to this leak.. and then recheck the file to see that Cppcheck still shows the warning. If warning is not shown then some #include or function you removed IS somehow related. Then maybe you can try to remove unrelated statements etc.
Then a ticket should be reported in our issue tracker (http://trac.cppcheck.net) so we can fix the problem.
E.g. this produces a wrong memleak warning on str.
Last edit: Reini Urban 2023-02-07