@@ -32,18 +32,18 @@ HANDLE *thread_handles;
3232
3333typedef struct
3434{
35- char log_file [ MAXPGPATH ] ;
36- char opt_log_file [ MAXPGPATH ] ;
37- char cmd [ MAX_STRING ] ;
35+ char * log_file ;
36+ char * opt_log_file ;
37+ char * cmd ;
3838}exec_thread_arg ;
3939
4040typedef struct
4141{
4242DbInfoArr * old_db_arr ;
4343DbInfoArr * new_db_arr ;
44- char old_pgdata [ MAXPGPATH ] ;
45- char new_pgdata [ MAXPGPATH ] ;
46- char old_tablespace [ MAXPGPATH ] ;
44+ char * old_pgdata ;
45+ char * new_pgdata ;
46+ char * old_tablespace ;
4747}transfer_thread_arg ;
4848
4949exec_thread_arg * * exec_thread_args ;
@@ -113,10 +113,12 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
113113pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
114114#else
115115if (thread_handles == NULL )
116+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
117+
118+ if (exec_thread_args == NULL )
116119{
117120int i ;
118121
119- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
120122exec_thread_args = pg_malloc (user_opts .jobs * sizeof (exec_thread_arg * ));
121123
122124/*
@@ -125,16 +127,22 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
125127 * thread different from the one that allocated it.
126128 */
127129for (i = 0 ;i < user_opts .jobs ;i ++ )
128- exec_thread_args [i ]= pg_malloc (sizeof (exec_thread_arg ));
130+ exec_thread_args [i ]= pg_malloc0 (sizeof (exec_thread_arg ));
129131}
130132
131133/* use first empty array element */
132134new_arg = exec_thread_args [parallel_jobs - 1 ];
133135
134136/* Can only pass one pointer into the function, so use a struct */
135- strcpy (new_arg -> log_file ,log_file );
136- strcpy (new_arg -> opt_log_file ,opt_log_file );
137- strcpy (new_arg -> cmd ,cmd );
137+ if (new_arg -> log_file )
138+ pg_free (new_arg -> log_file );
139+ new_arg -> log_file = pg_strdup (log_file );
140+ if (new_arg -> opt_log_file )
141+ pg_free (new_arg -> opt_log_file );
142+ new_arg -> opt_log_file = opt_log_file ?pg_strdup (opt_log_file ) :NULL ;
143+ if (new_arg -> cmd )
144+ pg_free (new_arg -> cmd );
145+ new_arg -> cmd = pg_strdup (cmd );
138146
139147child = (HANDLE )_beginthreadex (NULL ,0 , (void * )win32_exec_prog ,
140148new_arg ,0 ,NULL );
@@ -219,10 +227,12 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
219227pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
220228#else
221229if (thread_handles == NULL )
230+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
231+
232+ if (transfer_thread_args == NULL )
222233{
223234int i ;
224235
225- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
226236transfer_thread_args = pg_malloc (user_opts .jobs * sizeof (transfer_thread_arg * ));
227237
228238/*
@@ -231,7 +241,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
231241 * thread different from the one that allocated it.
232242 */
233243for (i = 0 ;i < user_opts .jobs ;i ++ )
234- transfer_thread_args [i ]= pg_malloc (sizeof (transfer_thread_arg ));
244+ transfer_thread_args [i ]= pg_malloc0 (sizeof (transfer_thread_arg ));
235245}
236246
237247/* use first empty array element */
@@ -240,9 +250,15 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
240250/* Can only pass one pointer into the function, so use a struct */
241251new_arg -> old_db_arr = old_db_arr ;
242252new_arg -> new_db_arr = new_db_arr ;
243- strcpy (new_arg -> old_pgdata ,old_pgdata );
244- strcpy (new_arg -> new_pgdata ,new_pgdata );
245- strcpy (new_arg -> old_tablespace ,old_tablespace );
253+ if (new_arg -> old_pgdata )
254+ pg_free (new_arg -> old_pgdata );
255+ new_arg -> old_pgdata = pg_strdup (old_pgdata );
256+ if (new_arg -> new_pgdata )
257+ pg_free (new_arg -> new_pgdata );
258+ new_arg -> new_pgdata = pg_strdup (new_pgdata );
259+ if (new_arg -> old_tablespace )
260+ pg_free (new_arg -> old_tablespace );
261+ new_arg -> old_tablespace = old_tablespace ?pg_strdup (old_tablespace ) :NULL ;
246262
247263child = (HANDLE )_beginthreadex (NULL ,0 , (void * )win32_transfer_all_new_dbs ,
248264new_arg ,0 ,NULL );