bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory leak in getprotobyname()


From: Roman Fleysher
Subject: Re: memory leak in getprotobyname()
Date: Tue, 2 Dec 2003 09:59:46 -0500

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");

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<============================






reply via email to

[Prev in Thread] Current Thread [Next in Thread]