Before creating a new issue in the "trac" system, I would like to make sure
this is not the expected behaviour.
The next piece of C code generates a memoryleak error:
* START *****
T2 x;
void f(void)
{
x.a = (int *) malloc(sizeof(int) * 10);
if (x.a != NULL)
{
free(x.a);
x.a = NULL;
}
} * END *****
$ cppcheck test.c
Checking test.c... [test.c:11]: (error) Memory leak: a
Note that the "T2" type is unknown.
If, instead of an "unknown" type, we use a well defined one, then the error
dissapears:
* START ****
typedef struct
{
int a;
} T;
T x;
void f(void)
{
x.a = (int *) malloc(sizeof(int) * 10);
if (x.a != NULL)
{
free(x.a);
x.a = NULL;
}
} * END *****
I known I should use #include's in the first example and tell cppcheck
where to look for the header files where the type is defined. However, when
the type is not defined, is it the expected behaviour to generate a
memoryleak error? What's the logic behind this decission?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Before creating a new issue in the "trac" system, I would like to make sure
this is not the expected behaviour.
The next piece of C code generates a memoryleak error:
* START *****
T2 x;
void f(void)
{
x.a = (int *) malloc(sizeof(int) * 10);
if (x.a != NULL)
{
free(x.a);
x.a = NULL;
}
}
* END *****
$ cppcheck test.c
Checking test.c...
[test.c:11]: (error) Memory leak: a
Note that the "T2" type is unknown.
If, instead of an "unknown" type, we use a well defined one, then the error
dissapears:
* START ****
typedef struct
{
int a;
} T;
T x;
void f(void)
{
x.a = (int *) malloc(sizeof(int) * 10);
if (x.a != NULL)
{
free(x.a);
x.a = NULL;
}
}
* END *****
I known I should use #include's in the first example and tell cppcheck
where to look for the header files where the type is defined. However, when
the type is not defined, is it the expected behaviour to generate a
memoryleak error? What's the logic behind this decission?
Thanks!
That is a false positive. Please report it in our issue tracker.