Hi,
I have recently started using SPLint. I have a doubt regarding a warning that I am getting. For the code below:


#include <stdio.h>
#include <stdlib.h>

struct m {
/*@only@*//*@null@*/int *a;
/*@only@*//*@null@*/int *b;
};

/*@null@*/struct m *xyz=NULL;

void test (void)
{
xyz=(struct m*)malloc (sizeof(struct m));
if (xyz==NULL)return;
xyz->a=0;
return;
}


I am getting a warning:
try6.c:15:1: Only storage xyz->a (type int *) not released before
assignment: xyz->a = 0
A memory leak has been detected. Only-qualified storage is not released before the last reference to it is lost. (Use -mustfreeonly to inhibit warning)


My doubt is, after allocating memory for a pointer, it is a general practice to initialise its contents (in this case, the elements of structure m) to default values, which in this case is NULL for element a of struct m. Why does splint raise a warning when we try to initialise that (element a of struct m)to its default value of NULL, just after allocation. Also, in case we want to get rid of this warning, what should I do.

Thanks and Regards,
Awan




Reply via email to