@@ -140,16 +140,16 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
140140
141141 /* Initialize attributes for task_spawn(). */
142142
143- ret = posix_spawn_file_actions_init ( & file_actions );
143+ ret = posix_spawnattr_init ( & attr );
144144 if (ret != 0 )
145145 {
146146 goto errout_with_errno ;
147147 }
148148
149- ret = posix_spawnattr_init ( & attr );
149+ ret = posix_spawn_file_actions_init ( & file_actions );
150150 if (ret != 0 )
151151 {
152- goto errout_with_errno ;
152+ goto errout_with_attrs ;
153153 }
154154
155155 /* Set the correct task size and priority */
@@ -158,13 +158,13 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
158158 ret = posix_spawnattr_setschedparam (& attr , & param );
159159 if (ret != 0 )
160160 {
161- goto errout_with_errno ;
161+ goto errout_with_actions ;
162162 }
163163
164164 ret = task_spawnattr_setstacksize (& attr , builtin -> stacksize );
165165 if (ret != 0 )
166166 {
167- goto errout_with_errno ;
167+ goto errout_with_actions ;
168168 }
169169
170170 /* If robin robin scheduling is enabled, then set the scheduling policy
@@ -175,21 +175,21 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
175175 ret = posix_spawnattr_setschedpolicy (& attr , SCHED_RR );
176176 if (ret != 0 )
177177 {
178- goto errout_with_errno ;
178+ goto errout_with_actions ;
179179 }
180180
181181 ret = posix_spawnattr_setflags (& attr ,
182182 POSIX_SPAWN_SETSCHEDPARAM |
183183 POSIX_SPAWN_SETSCHEDULER );
184184 if (ret != 0 )
185185 {
186- goto errout_with_errno ;
186+ goto errout_with_actions ;
187187 }
188188#else
189189 ret = posix_spawnattr_setflags (& attr , POSIX_SPAWN_SETSCHEDPARAM );
190190 if (ret != 0 )
191191 {
192- goto errout_with_errno ;
192+ goto errout_with_actions ;
193193 }
194194#endif
195195
@@ -204,7 +204,7 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
204204 if (ret != 0 )
205205 {
206206 sdbg ("ERROR: posix_spawn_file_actions_addopen failed: %d\n" , ret );
207- goto errout_with_errno ;
207+ goto errout_with_actions ;
208208 }
209209 }
210210
@@ -216,16 +216,28 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
216216 if (ret != 0 )
217217 {
218218 sdbg ("ERROR: task_spawn failed: %d\n" , ret );
219- goto errout_with_errno ;
219+ goto errout_with_actions ;
220220 }
221221
222+ /* Free attibutes and file actions. Ignoring return values in the case
223+ * of an error.
224+ */
225+
222226 /* Return the task ID of the new task if the task was sucessfully
223227 * started. Otherwise, ret will be ERROR (and the errno value will
224228 * be set appropriately).
225229 */
226230
231+ (void )posix_spawn_file_actions_destroy (& file_actions );
232+ (void )posix_spawnattr_destroy (& attr );
227233 return pid ;
228234
235+ errout_with_actions :
236+ (void )posix_spawn_file_actions_destroy (& file_actions );
237+
238+ errout_with_attrs :
239+ (void )posix_spawnattr_destroy (& attr );
240+
229241errout_with_errno :
230242 set_errno (ret );
231243 return ERROR ;
0 commit comments