[splint-discuss] About onlytrans
Ma Li Yu
lyma at cct-tech.com.sg
Wed Dec 12 19:22:28 PST 2007
Hi,
Currently I faced below issue:
pdis.c: (in function Store_Key)
pdis.c(115,3): Only storage assigned to unqualified static:
Key_ptr = (KEY_BUFFERING
*)malloc(sizeof(KEY_BUFFERING))
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)
This is definition of Key_ptr. It was defined outside of function
Store_Key:
Static KEY_BUFFERING * Key_ptr;
It tries to tell me that it could lead to a memory leak. But I did not
understand it. The strange thing is that splint would not complain any
more after I changed to below code:
KEY_BUFFERING * temp_ptr; //Define inside function Store_Key
....
temp_ptr = (KEY_BUFFERING *)malloc(sizeof(KEY_BUFFERING));
Key_ptr = temp_ptr;
But I think it is not optimized. Above code is simpler and take less
code size. What did u think?
Regards
MA LIYU Mark
R&D Software Engineer
CCT Tech Singapore Pte Limited
Tel: 65-6240 6823
Fax: 65-6444 7848
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.cs.virginia.edu/pipermail/splint-discuss/attachments/20071213/66130d2f/attachment.html
More information about the splint-discuss
mailing list