Fix gethostbyname_r example. Fixes bug 2801.
authorOndřej Bílka <neleai@seznam.cz>
Fri, 25 Oct 2013 17:16:08 +0000 (19:16 +0200)
committerOndřej Bílka <neleai@seznam.cz>
Fri, 25 Oct 2013 17:17:58 +0000 (19:17 +0200)
ChangeLog
NEWS
manual/socket.texi

index 3e0e025..c2e5261 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2013-10-25   Ondřej Bílka  <neleai@seznam.cz>
 
+       [BZ 2801]
+       * manual/socket.texi (Host Names): Fix gethostbyname_r example.
+
+2013-10-25   Ondřej Bílka  <neleai@seznam.cz>
+
        [BZ #14876]
        * time/strptime_l.c (__strptime_internal): 14876 Read timezone entry.
        * time/tst-strptime.c (day_tests): Add testcase.
diff --git a/NEWS b/NEWS
index 5055324..0b7e9f7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,14 +9,14 @@ Version 2.19
 
 * The following bugs are resolved with this release:
 
-  156, 431, 832, 10278, 13028, 13982, 13985, 14029, 14155, 14547, 14699,
-  14876, 14910, 15048, 15218, 15277, 15308, 15362, 15400, 15427, 15522,
-  15531, 15532, 15608, 15609, 15610, 15632, 15640, 15670, 15672, 15680,
-  15681, 15723, 15734, 15735, 15736, 15748, 15749, 15754, 15760, 15764,
-  15797, 15825, 15844, 15847, 15849, 15855, 15856, 15857, 15859, 15867,
-  15886, 15887, 15890, 15892, 15893, 15895, 15897, 15905, 15909, 15919,
-  15921, 15923, 15939, 15948, 15963, 15966, 15988, 16032, 16034, 16036,
-  16041, 16072, 16074.
+  156, 431, 832, 2801, 10278, 13028, 13982, 13985, 14029, 14155, 14547,
+  14699, 14876, 14910, 15048, 15218, 15277, 15308, 15362, 15400, 15427,
+  15522, 15531, 15532, 15608, 15609, 15610, 15632, 15640, 15670, 15672,
+  15680, 15681, 15723, 15734, 15735, 15736, 15748, 15749, 15754, 15760,
+  15764, 15797, 15825, 15844, 15847, 15849, 15855, 15856, 15857, 15859,
+  15867, 15886, 15887, 15890, 15892, 15893, 15895, 15897, 15905, 15909,
+  15919, 15921, 15923, 15939, 15948, 15963, 15966, 15988, 16032, 16034,
+  16036, 16041, 16072, 16074.
 
 * CVE-2012-4412 The strcoll implementation caches indices and rules for
   large collation sequences to optimize multiple passes.  This cache
index 25c35c4..4c7e623 100644 (file)
@@ -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;