It is probably some detail there in your code that makes Cppcheck confused.
If you copy paste a function with FP to a different file and check that.. does it show the warning still? If it does then it's some detail in the function. Otherwise it seems there is something about a function call or type etc.
I would like that you reduce your code by repeating these steps:
1. remove some code
2. run cppcheck on the file
3. if the FP is not shown => undo changes
Start with large chunks of code. I often start by removing #includes. then I remove large blocks of code such as types/functions/etc.. when I do this, I remove stuff until every statement, every identifier and every operation etc is needed to reproduce the FP.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem is that there is a return in the function when an error occurs. It should never happen, but if it occurs then I return out of the function. The hTileFont won't be deallocated then (actually, the application shuts down when this function fails so nothing matters then anymore).
Thanks for the help.
Last edit: Sander Bouwhuis 2015-06-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Why does the following code produce a resourceLeak error for hTileFont?
I allocate memory with CreateFont() and deallocate with DeleteObject().
~~~~~~
HFONT hTileFont = NULL;
// ...
hTileFont = CreateFont(i32TileFontHeight, 0, 0, 0, i32TileFontWeight, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH | FF_DONTCARE, pwcFontFace);
// ...
// Create the tiles
InitializeTile(&m_btnAccessControlAccessControl, MODULE_ACCESSCONTROL, L"Access_control", pwcIniFile, true, hTileFont, bTileBorder);
// ...
// Free the resources
if(hTileFont)
DeleteObject(hTileFont);
sounds like a bug. but I fail to reproduce. I use this command:
Tried with this code:
I have it on a lot of places in my source code. Every time it thinks there is a resource leak. I don't understand why.
I use the GUI on Windows. Maybe that makes a difference?
Last edit: Sander Bouwhuis 2015-06-19
It is probably some detail there in your code that makes Cppcheck confused.
If you copy paste a function with FP to a different file and check that.. does it show the warning still? If it does then it's some detail in the function. Otherwise it seems there is something about a function call or type etc.
I would like that you reduce your code by repeating these steps:
1. remove some code
2. run cppcheck on the file
3. if the FP is not shown => undo changes
Start with large chunks of code. I often start by removing #includes. then I remove large blocks of code such as types/functions/etc.. when I do this, I remove stuff until every statement, every identifier and every operation etc is needed to reproduce the FP.
It should not make a difference.
Can you try to reproduce a FP with the command line cppcheck also? Try some command such as:
Ooooooooooooooooh, shoot! I understand now.
The problem is that there is a return in the function when an error occurs. It should never happen, but if it occurs then I return out of the function. The hTileFont won't be deallocated then (actually, the application shuts down when this function fails so nothing matters then anymore).
Thanks for the help.
Last edit: Sander Bouwhuis 2015-06-23