[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: memory leak in getprotobyname()
From: |
Daniel Jacobowitz |
Subject: |
Re: memory leak in getprotobyname() |
Date: |
Tue, 2 Dec 2003 10:49:54 -0500 |
User-agent: |
Mutt/1.5.1i |
On Tue, Dec 02, 2003 at 09:59:46AM -0500, Roman Fleysher wrote:
>
> I am not an expert on the subject, but it looks as if getprotobyname()
> allocates a structure and returns a pointer to it. Thus, each time you
> call it, new structure is allocated and new pointer is returned. You can
> check it with
>
> if(getprotobyname("tcp") != getprotobyname("tcp"))
> printf("Each call allocates new structure
> (assuming these were not NULL's)\n");
That's incorrect. From the manual:
You can use `getprotobyname' and `getprotobynumber' to search the
protocols database for a specific protocol. The information is
returned in a statically-allocated structure; you must copy the
information if you need to save it across calls.
>
> Roman
>
> > ========================8<============================
> > #include <netdb.h>
> > #include <stdio.h>
> >
> > int main(void) {
> > int i;
> > struct protoent *protocol=NULL;
> >
> > for (i=0; i<200000; i++) {
> > protocol=getprotobyname("tcp");
> > }
> > printf("\n RESULT : %02x \n",protocol->p_proto);
> >
> > return 0;
> > }
> > ========================8<============================
>
>
>
> --
> To UNSUBSCRIBE, email to address@hidden
> with a subject of "unsubscribe". Trouble? Contact address@hidden
>
>
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer