1414 *
1515 * The possible states of a `tempfile` object are as follows:
1616 *
17- * - Uninitialized. In this state the object's `on_list` field must be
18- * zero but the rest of its contents need not be initialized. As
19- * soon as the object is used in any way, it is irrevocably
20- * registered in `tempfile_list`, and `on_list` is set.
17+ * - Inactive/unallocated. The only way to get a tempfile is via a creation
18+ * function like create_tempfile(). Once allocated, the tempfile is on the
19+ * global tempfile_list and considered active.
2120 *
2221 * - Active, file open (after `create_tempfile()` or
2322 * `reopen_tempfile()`). In this state:
2423 *
2524 * - the temporary file exists
26- * - `active` is set
2725 * - `filename` holds the filename of the temporary file
2826 * - `fd` holds a file descriptor open for writing to it
2927 * - `fp` holds a pointer to an open `FILE` object if and only if
3533 * `fd` is -1, and `fp` is `NULL`.
3634 *
3735 * - Inactive (after `delete_tempfile()`, `rename_tempfile()`, or a
38- * failed attempt to create a temporary file). In this state:
39- *
40- * - `active` is unset
41- * - `filename` is empty (usually, though there are transitory
42- * states in which this condition doesn't hold). Client code should
43- * *not* rely on the filename being empty in this state.
44- * - `fd` is -1 and `fp` is `NULL`
45- * - the object is removed from `tempfile_list` (but could be used again)
36+ * failed attempt to create a temporary file). The struct is removed from
37+ * the global tempfile_list and deallocated.
4638 *
4739 * A temporary file is owned by the process that created it. The
4840 * `tempfile` has an `owner` field that records the owner's PID. This
@@ -86,8 +78,6 @@ static void remove_tempfiles(int in_signal_handler)
8678 else
8779 unlink_or_warn (p -> filename .buf );
8880 remove_template_directory (p , in_signal_handler );
89-
90- p -> active = 0 ;
9181 }
9282}
9383
@@ -108,7 +98,6 @@ static struct tempfile *new_tempfile(void)
10898 struct tempfile * tempfile = xmalloc (sizeof (* tempfile ));
10999 tempfile -> fd = -1 ;
110100 tempfile -> fp = NULL ;
111- tempfile -> active = 0 ;
112101 tempfile -> owner = 0 ;
113102 INIT_LIST_HEAD (& tempfile -> list );
114103 strbuf_init (& tempfile -> filename , 0 );
@@ -120,9 +109,6 @@ static void activate_tempfile(struct tempfile *tempfile)
120109{
121110 static int initialized ;
122111
123- if (is_tempfile_active (tempfile ))
124- BUG ("activate_tempfile called for active object" );
125-
126112 if (!initialized ) {
127113 sigchain_push_common (remove_tempfiles_on_signal );
128114 atexit (remove_tempfiles_on_exit );
@@ -131,15 +117,13 @@ static void activate_tempfile(struct tempfile *tempfile)
131117
132118 volatile_list_add (& tempfile -> list , & tempfile_list );
133119 tempfile -> owner = getpid ();
134- tempfile -> active = 1 ;
135120}
136121
137122static void deactivate_tempfile (struct tempfile * tempfile )
138123{
139- tempfile -> active = 0 ;
124+ volatile_list_del ( & tempfile -> list ) ;
140125 strbuf_release (& tempfile -> filename );
141126 free (tempfile -> directory );
142- volatile_list_del (& tempfile -> list );
143127 free (tempfile );
144128}
145129
0 commit comments