[splint-discuss] memory leak detection
Roland Illig
roland.illig at gmx.de
Sun Nov 2 05:34:27 EST 2003
On Sat, Nov 01, 2003 at 09:58:46PM -0500, David Evans wrote:
>
> Splint's analysis isn't sophisticated enough to figure this out. If you
> do,
>
> free(this_string);
> this_string = NULL;
>
> it will prevent the warning.
I just checked the manual, and in clause 5.2.1#5 it states that
"After the release obligation is transferred, the original reference
is a dead pointer and the storage it points to may not be used."
5.2.1#3 says:
* assign it to an external reference declared with an only annotation
According to these statements, the following program should be ok,
shouldn't it?
------------------------------------------------------------------
typedef /*@only@*/ /*@null@*/ char *cstring;
/*@external@*/ extern cstring make_string(const char *) /*@*/;
extern int main(void)
{
cstring oldstr = NULL;
cstring newstr = make_string("newstr");
if (oldstr == NULL) {
oldstr = newstr;
/* oldstr should be live */
/* newstr should be dead */
} else {
free(oldstr);
oldstr = make_string("oldstr");
/* oldstr should be live */
free(newstr);
/* newstr should be dead */
}
free(oldstr);
return 0;
}
------------------------------------------------------------------
Roland
More information about the splint-discuss
mailing list