[LEDE-DEV] [PATCH] fstools: Fix some errors detected by cppcheck
Arjen de Korte
arjen+lede at de-korte.org
Mon Dec 11 13:22:52 PST 2017
Citeren Jonas Gorski <jonas.gorski at gmail.com>:
> On 11 December 2017 at 10:04, Rosen Penev <rosenp at gmail.com> wrote:
>> Mainly plugging memory leaks. Size reduction as well. The calloc
>> change accounts for 272 bytes on this machine for some reason...
>
> Please state the exact errors found by cppcheck so we don't have to
> guess what it found.
I tried to replicate what Rosen did, but in my case cppcheck came up
with only two errors:
[libfstools/rootdisk.c:175]: (error) Resource leak: f
[libfstools/ubi.c:72]: (error) Resource leak: f
These look like actual leaks, so this *may* be worth fixing. It could
also be the conditions never occur (so these never leak anything). The
proposed changes for these two errors look sane though.
[block.c:1087] -> [block.c:1091]: (warning) Either the condition
'!pr' is redundant or there is possible null pointer dereference: pr.
This one has merit too. There is no point in doing a NULL pointer
check after using that pointer a few lines before.
[blockd.c:119]: (warning) Possible null pointer dereference: device
[blockd.c:127]: (warning) Possible null pointer dereference: device
[blockd.c:130]: (warning) Possible null pointer dereference: device
I'm not so sure about these warnings. It doesn't seem possible that
*both* device_n and device_o are NULL, which would be required to
actually cause a NULL pointer dereference here. This might be fixed
cleaner by changing
211 } else {
to
211 } else if (device_o) {
The remainder of the warnings might be 'fixed' to shut-up cppcheck,
but don't actually change anything.
More information about the Lede-dev
mailing list