olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1234449-3.patch

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