[splint-discuss] Implicitly only storage not released
Wenzel, Bodo
Wenzel at bbr-vt.de
Mon Feb 20 00:26:57 PST 2012
Hi Robert,
You didn't mention your command line for Splint, so I used no options.
The source looks like not knowing how memory allocation and pointers are working (no offend). Therefore it's a bit difficult to know what is ment. Anyway, here we go:
> Implicitly only storage options->min_string (type char *) not released
> before assignment: options->min_string = min_string
> 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)
Splint assumes that pointers without annotation are the only reference to their memory spaces. By assigning a new address, this old pointer is lost. If annotated by "dependent" these pointers are not responsible for the memory.
> Kept storage min_string passed as only param: free (min_string) storage
> is transferred to a non-temporary reference after being passed as keep
> parameter. The storage may be released or new aliases created. (Use
> -kepttrans to inhibit warning)
Here Splint found an actual error which is probably the root of your crashes. Releasing this memory but keeping the pointer in options->min_string is an error if the memory pointed to is used later.
Splint does not report this error after annotating "options->min_string" any more, unfortunately.
To get no reports at all, I had to add an "unused" annotation for "argc" and to release the memory of "charset".
Cheers,
Bodo
typedef struct opts_struct {
/*@ dependent @*/ char *low_charset;
size_t clen;
/*@ dependent @*/ char *startstring;
size_t starthere;
/*@ dependent @*/ char *min_string;
} options_type;
/* ... */
int main(/*@ unused @*/ int argc, char **argv) {
/* ... */
fill_strings(options);
free(charset);
free(options);
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20120220/c73e4ee4/attachment-0001.html
More information about the splint-discuss
mailing list