aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorOndřej Bílka <neleai@seznam.cz>2013-10-25 19:16:08 +0200
committerOndřej Bílka <neleai@seznam.cz>2013-10-25 19:17:58 +0200
commit151659f6371ce39a488fd132a5c8ce5e3bba983c (patch)
treef3a90009fd76631bb2419cfe912580afe071694c /manual
parent10b0f26b1950f8d38a5846b80833564df3c5b582 (diff)
downloadglibc-151659f6371ce39a488fd132a5c8ce5e3bba983c.zip
glibc-151659f6371ce39a488fd132a5c8ce5e3bba983c.tar.gz
glibc-151659f6371ce39a488fd132a5c8ce5e3bba983c.tar.bz2
Fix gethostbyname_r example. Fixes bug 2801.
Diffstat (limited to 'manual')
-rw-r--r--manual/socket.texi8
1 files changed, 5 insertions, 3 deletions
diff --git a/manual/socket.texi b/manual/socket.texi
index 25c35c4..4c7e623 100644
--- a/manual/socket.texi
+++ b/manual/socket.texi
@@ -1307,23 +1307,25 @@ Here's a small example:
struct hostent *
gethostname (char *host)
@{
- struct hostent hostbuf, *hp;
+ struct hostent *hostbuf, *hp;
size_t hstbuflen;
char *tmphstbuf;
int res;
int herr;
+ hostbuf = malloc (sizeof (struct hostent));
hstbuflen = 1024;
- /* Allocate buffer, remember to free it to avoid memory leakage. */
tmphstbuf = malloc (hstbuflen);
- while ((res = gethostbyname_r (host, &hostbuf, tmphstbuf, hstbuflen,
+ while ((res = gethostbyname_r (host, hostbuf, tmphstbuf, hstbuflen,
&hp, &herr)) == ERANGE)
@{
/* Enlarge the buffer. */
hstbuflen *= 2;
tmphstbuf = realloc (tmphstbuf, hstbuflen);
@}
+
+ free (tmphstbuf);
/* Check for errors. */
if (res || hp == NULL)
return NULL;