[splint-discuss] warning related to -onlytrans flag
Ludolf Holzheid
lholzheid at bihl-wiedemann.de
Sun Mar 30 03:29:11 PST 2008
On Sun, 2008-03-30 14:07:14 +0530, Vishal Bayskar wrote:
> Dear All,
>
> I am puzzled why splint is giving warning
>
>
>
> Following line of code is used in program
>
> temp_file = (char *)calloc(10, sizeof(char))
>
> Here temp_file is static char *temp_file;
>
>
> And after this line, check is used like
>
> if (temp_file==NULL)
> {
> return 1;
> }
>
>
> In program memory allocation (calloc) to temp_file is used only one time
>
>
> But splint is showing the following warning
>
> Only storage assigned to unqualified static:
> temp_file = (char *)calloc(10, sizeof(char))
>
> The only reference to this storage is transferred to another reference
> (e.g.,
> by returning it) that does not have the only annotation. This may lead
> to a
> memory leak, since the new reference is not necessarily released. (Use
> -onlytrans to inhibit warning)
>
> Pleas help me understanding why this warning is coming how to solve this
> without using flag onlytrans
Vishal,
the concept /*@only@*/ annotation is explained in section 5.2.1 of the
manual. In your case, you could declare the temp_file pointer as
/*@only@*/:
static char /*@only@*/ *temp_file = NULL;
Ludolf
--
---------------------------------------------------------------
Ludolf Holzheid Tel: +49 621 339960
Bihl+Wiedemann GmbH Fax: +49 621 3392239
Floßwörthstraße 41 e-mail: lholzheid at bihl-wiedemann.de
D-68199 Mannheim, Germany
---------------------------------------------------------------
More information about the splint-discuss
mailing list