]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Fix a race condition: freed storage accessed during a signal handler.
authorJim Meyering <jim@meyering.net>
Mon, 19 Feb 2001 08:52:53 +0000 (08:52 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 19 Feb 2001 08:52:53 +0000 (08:52 +0000)
(struct tempnode.next): Now volatile.
(zaptemp): Free the file name after removing it from the temp list,
not before, because a signal can arrive between the two actions
and cleanup () traverses the list.

src/sort.c

index affde7b21e687ec85db7df5c051006123130d580..5672b5bbb7a88fdffa984b73089211bf8abd324e 100644 (file)
@@ -343,7 +343,7 @@ Set LC_ALL=C to get the traditional sort order that uses native byte values.\n\
 static struct tempnode
 {
   char *name;
-  struct tempnode *next;
+  struct tempnode * volatile next;
 } temphead;
 
 /* Clean up any remaining temporary files. */
@@ -503,8 +503,8 @@ zaptemp (const char *name)
     {
       temp = node->next;
       unlink (temp->name);
-      free (temp->name);
       node->next = temp->next;
+      free (temp->name);
       free ((char *) temp);
     }
 }