David Evans
Sat, 28 Sep 2002 10:29:10 -0700
Hi Sripriya,
What you need is an /*@observer@*/ annotation on get_hname:
/*@observer@*/ const char* get_hname(const u_char *);
Without it, the default /*@only@*/ annotation is assumed for the
declaration of get_hname, and splint complains about an apparent memory
leak when the result of get_hname is passed as a printf parameter:
printf(" -> who-has %s ",get_hname((const u_char
The const C keyword should be enough to imply this, but Splint doesn't
interpret it.
--- Dave
On Thu, 26 Sep 2002, Sripriya Subramanian wrote:
> Hi all,
> I am a new user to Splint. I have a Sniffer code on which i am running
> splint. Splint is throwing memory leak problems and I am not able to
> solve it.
>
> /*** util.c ****/
> const char* get_hname(const u_char *ap)
> {
> const struct hostent *hp;
> u_int32_t addr;
> memcpy(&addr, ap, sizeof(addr));
> if(nflag>0)
> {
> hp = gethostbyaddr((char *) &addr, 4, AF_INET);
> if(hp)
> return (hp->h_name);
> }
> return(get_haddr(addr));
> }
>
> /**** arp.c **** - print arp packets/
> void print_ARP (const u_char *pdata, /*@unused@*/ u_int length)
> {
> struct ARP_header *arph = (struct ARP_header *)pdata;
> .
> .
> .
> switch(ntohs(arph->ar_op))
> {
> case ARPOP_REQUEST:
> printf("arp:request");
> if(vflag>0)
> {
> *)arph->ar_dpa));
> printf("tell %s", get_hname((const u_char *)arph->ar_spa));
> }
> break;
>
> default:
> printf("arp \n");
> break;
> }
> }
>
> arp.c: (in function print_ARP)
> arp.c:22:29: New fresh storage (type char *) passed as implicitly temp (not
> released): get_hname((const u_char *)arph->ar_dpa)
> A memory leak has been detected. Storage allocated locally is not released
> before the last reference to it is lost. (Use -mustfreefresh to inhibit
> warning)
>
>
> Can somebody let me know what sort of annotations will help me in this
> situation and it will be great if somebody can explain me the situation.
>
> Sripriya Subramanian
>