Blame SOURCES/glibc-rh1234449-3.patch

147e83
commit cc8dcf96e71dd643f929e32150904cd6ad69efa8
147e83
Author: Florian Weimer <fweimer@redhat.com>
147e83
Date:   Mon Apr 27 15:41:03 2015 +0200
147e83
147e83
    test-skeleton: Support temporary files without memory leaks [BZ#18333]
147e83
    
147e83
    add_temp_file now makes a copy which is freed by delete_temp_files.
147e83
    Callers to create_temp_file can now free the returned file name to
147e83
    avoid the memory leak.  These changes do not affect the leak behavior
147e83
    of existing code.
147e83
147e83
    Also address a NULL pointer derefence in tzset after a memory allocation
147e83
    failure, found during testing.
147e83
147e83
diff --git a/test-skeleton.c b/test-skeleton.c
147e83
index 7a8ddfa..43fc236 100644
147e83
--- a/test-skeleton.c
147e83
+++ b/test-skeleton.c
147e83
@@ -73,7 +73,7 @@ static const char *test_dir;
147e83
 struct temp_name_list
147e83
 {
147e83
   struct qelem q;
147e83
-  const char *name;
147e83
+  char *name;
147e83
 } *temp_name_list;
147e83
 
147e83
 /* Add temporary files in list.  */
147e83
@@ -83,14 +83,17 @@ add_temp_file (const char *name)
147e83
 {
147e83
   struct temp_name_list *newp
147e83
     = (struct temp_name_list *) calloc (sizeof (*newp), 1);
147e83
-  if (newp != NULL)
147e83
+  char *newname = strdup (name);
147e83
+  if (newp != NULL && newname != NULL)
147e83
     {
147e83
-      newp->name = name;
147e83
+      newp->name = newname;
147e83
       if (temp_name_list == NULL)
147e83
 	temp_name_list = (struct temp_name_list *) &newp->q;
147e83
       else
147e83
 	insque (newp, temp_name_list);
147e83
     }
147e83
+  else
147e83
+    free (newp);
147e83
 }
147e83
 
147e83
 /* Delete all temporary files.  */
147e83
@@ -100,11 +103,19 @@ delete_temp_files (void)
147e83
   while (temp_name_list != NULL)
147e83
     {
147e83
       remove (temp_name_list->name);
147e83
-      temp_name_list = (struct temp_name_list *) temp_name_list->q.q_forw;
147e83
+      free (temp_name_list->name);
147e83
+
147e83
+      struct temp_name_list *next
147e83
+	= (struct temp_name_list *) temp_name_list->q.q_forw;
147e83
+      free (temp_name_list);
147e83
+      temp_name_list = next;
147e83
     }
147e83
 }
147e83
 
147e83
-/* Create a temporary file.  */
147e83
+/* Create a temporary file.  Return the opened file descriptor on
147e83
+   success, or -1 on failure.  Write the file name to *FILENAME if
147e83
+   FILENAME is not NULL.  In this case, the caller is expected to free
147e83
+   *FILENAME.  */
147e83
 static int
147e83
 __attribute__ ((unused))
147e83
 create_temp_file (const char *base, char **filename)
147e83
@@ -132,6 +143,8 @@ create_temp_file (const char *base, char **filename)
147e83
   add_temp_file (fname);
147e83
   if (filename != NULL)
147e83
     *filename = fname;
147e83
+  else
147e83
+    free (fname);
147e83
 
147e83
   return fd;
147e83
 }
147e83
diff --git a/time/tzset.c b/time/tzset.c
147e83
--- a/time/tzset.c
147e83
+++ b/time/tzset.c
147e83
@@ -202,7 +202,10 @@
147e83
 	return false;
147e83
     }
147e83
 
147e83
-  tz_rules[whichrule].name = __tzstring_len (start, len);
147e83
+  const char *name = __tzstring_len (start, len);
147e83
+  if (name == NULL)
147e83
+    return false;
147e83
+  tz_rules[whichrule].name = name;
147e83
 
147e83
   *tzp = p;
147e83
   return true;