@@ -32,18 +32,18 @@ HANDLE *thread_handles;
32
32
33
33
typedef struct
34
34
{
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 ;
38
38
}exec_thread_arg ;
39
39
40
40
typedef struct
41
41
{
42
42
DbInfoArr * old_db_arr ;
43
43
DbInfoArr * 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 ;
47
47
}transfer_thread_arg ;
48
48
49
49
exec_thread_arg * * exec_thread_args ;
@@ -113,10 +113,12 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
113
113
pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
114
114
#else
115
115
if (thread_handles == NULL )
116
+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
117
+
118
+ if (exec_thread_args == NULL )
116
119
{
117
120
int i ;
118
121
119
- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
120
122
exec_thread_args = pg_malloc (user_opts .jobs * sizeof (exec_thread_arg * ));
121
123
122
124
/*
@@ -125,16 +127,22 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
125
127
* thread different from the one that allocated it.
126
128
*/
127
129
for (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 ));
129
131
}
130
132
131
133
/* use first empty array element */
132
134
new_arg = exec_thread_args [parallel_jobs - 1 ];
133
135
134
136
/* 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 );
138
146
139
147
child = (HANDLE )_beginthreadex (NULL ,0 , (void * )win32_exec_prog ,
140
148
new_arg ,0 ,NULL );
@@ -219,10 +227,12 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
219
227
pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
220
228
#else
221
229
if (thread_handles == NULL )
230
+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
231
+
232
+ if (transfer_thread_args == NULL )
222
233
{
223
234
int i ;
224
235
225
- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
226
236
transfer_thread_args = pg_malloc (user_opts .jobs * sizeof (transfer_thread_arg * ));
227
237
228
238
/*
@@ -231,7 +241,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
231
241
* thread different from the one that allocated it.
232
242
*/
233
243
for (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 ));
235
245
}
236
246
237
247
/* use first empty array element */
@@ -240,9 +250,15 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
240
250
/* Can only pass one pointer into the function, so use a struct */
241
251
new_arg -> old_db_arr = old_db_arr ;
242
252
new_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 ;
246
262
247
263
child = (HANDLE )_beginthreadex (NULL ,0 , (void * )win32_transfer_all_new_dbs ,
248
264
new_arg ,0 ,NULL );