This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug manual/2801] New: Bug in gethostbyname_r() example

The gethostbyname_r() call accepts a pointer to a struct hostent (&hostbuf in
the example) and a pointer to a pointer to a struct hostent (&hp in the
example).  The result of the lookup is stored in hostbuf itself and hp is set to
point at that buffer on success.

The hp pointer is returned by the example function, but shouldn't be.  The thing
it points to has automatic scope and so won't exist when the function returns.

 The example function gethostname() should accept a (hostent*) as a parameter,
 The hostbuf variable should be allocated statically (although that would
 defeat the purpose of a gethostbyname_r() call in the first place)

There is a secondary problem in that there is no (direct) way that the pointer 
to the auxiliary buffer is passed back to the caller for later release of the 
allocated memory - leading to a memory leak.  Perhaps that could be ignored in
example code though?

           Summary: Bug in gethostbyname_r() example
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: minor
          Priority: P2
         Component: manual
        AssignedTo: roland at gnu dot org
        ReportedBy: andyparkins at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]