File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
#include "fpm_env.h"
13
13
#include "fpm.h"
14
+ #include "fpm_cleanup.h"
14
15
15
16
#ifndef HAVE_SETPROCTITLE
16
17
#if defined(__linux__ ) || defined(__APPLE__ )
@@ -194,6 +195,26 @@ static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp) /* {{{ */
194
195
}
195
196
/* }}} */
196
197
198
+
199
+ #ifndef HAVE_SETPROCTITLE
200
+ #if defined(__linux__ ) || defined(__APPLE__ )
201
+ /* Frees our copied environment variables. */
202
+ static void fpm_env_cleanup (int which , void * arg ) /* {{{ */
203
+ {
204
+ char * * allocated_environ = environ ;
205
+ if (allocated_environ ) {
206
+ environ = NULL ;
207
+ unsigned int i = 0 ;
208
+ while (allocated_environ [i ]) {
209
+ free (allocated_environ [i ]);
210
+ i ++ ;
211
+ }
212
+ free (allocated_environ );
213
+ }
214
+ }
215
+ #endif
216
+ #endif
217
+
197
218
int fpm_env_init_main (void )
198
219
{
199
220
struct fpm_worker_pool_s * wp ;
@@ -254,6 +275,10 @@ int fpm_env_init_main(void)
254
275
env_nb ++ ;
255
276
}
256
277
278
+ if (0 > fpm_cleanup_add (FPM_CLEANUP_PARENT_EXIT_MAIN , fpm_env_cleanup , 0 )) {
279
+ return -1 ;
280
+ }
281
+
257
282
if ((new_environ = malloc ((1U + env_nb ) * sizeof (char * ))) == NULL ) {
258
283
return -1 ;
259
284
}
You can’t perform that action at this time.
0 commit comments