@@ -63,6 +63,8 @@ void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry)
63
63
finish_command (& entry -> process );
64
64
65
65
hashmap_remove (hashmap , & entry -> ent , NULL );
66
+ FREE_AND_NULL (entry -> to_free );
67
+ entry -> cmd = NULL ;
66
68
}
67
69
68
70
static void subprocess_exit_handler (struct child_process * process )
@@ -100,6 +102,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
100
102
process -> trace2_child_class = "subprocess" ;
101
103
102
104
entry -> cmd = process -> args .v [0 ];
105
+ entry -> to_free = NULL ;
103
106
104
107
err = start_command (process );
105
108
if (err ) {
@@ -145,11 +148,13 @@ int subprocess_start_strvec(struct hashmap *hashmap,
145
148
process -> trace2_child_class = "subprocess" ;
146
149
147
150
sq_quote_argv_pretty (& quoted , argv -> v );
148
- entry -> cmd = strbuf_detach (& quoted , NULL );
151
+ entry -> cmd = entry -> to_free = strbuf_detach (& quoted , NULL );
149
152
150
153
err = start_command (process );
151
154
if (err ) {
152
155
error ("cannot fork to run subprocess '%s'" , entry -> cmd );
156
+ FREE_AND_NULL (entry -> to_free );
157
+ entry -> cmd = NULL ;
153
158
return err ;
154
159
}
155
160
@@ -158,6 +163,8 @@ int subprocess_start_strvec(struct hashmap *hashmap,
158
163
err = startfn (entry );
159
164
if (err ) {
160
165
error ("initialization for subprocess '%s' failed" , entry -> cmd );
166
+ FREE_AND_NULL (entry -> to_free );
167
+ entry -> cmd = NULL ;
161
168
subprocess_stop (hashmap , entry );
162
169
return err ;
163
170
}
0 commit comments