@@ -162,10 +162,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
162
162
int i ;
163
163
job_t * job ;
164
164
spi_response_t * r ;
165
- MemoryContext old ;
166
- MemoryContext mem = init_mem_ctx ("executor" );
167
-
168
- old = MemoryContextSwitchTo (mem );
165
+ MemoryContext old , mem ;
169
166
170
167
EE .n = 0 ;
171
168
EE .errors = NULL ;
@@ -178,6 +175,9 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
178
175
return 0 ;
179
176
}
180
177
178
+ mem = init_mem_ctx ("executor" );
179
+ old = MemoryContextSwitchTo (mem );
180
+
181
181
* status = shared -> status = SchdExecutorWork ;
182
182
shared -> message [0 ] = 0 ;
183
183
@@ -191,6 +191,9 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
191
191
shared -> worker_exit = true;
192
192
* status = shared -> status = SchdExecutorError ;
193
193
194
+ MemoryContextSwitchTo (old );
195
+ MemoryContextDelete (mem );
196
+
194
197
return -1 ;
195
198
}
196
199
current_job_id = job -> cron_id ;
@@ -211,6 +214,8 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
211
214
}
212
215
* status = shared -> worker_exit = true;
213
216
shared -> status = SchdExecutorError ;
217
+ MemoryContextSwitchTo (old );
218
+ MemoryContextDelete (mem );
214
219
return -2 ;
215
220
}
216
221
@@ -257,7 +262,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
257
262
destroy_spi_data (r );
258
263
ABORT_SPI_SNAP ();
259
264
SetConfigOption ("schedule.transaction_state" , "failure" , PGC_INTERNAL , PGC_S_SESSION );
260
- executor_onrollback (job , & EE );
265
+ executor_onrollback (mem , job , & EE );
261
266
262
267
break ;
263
268
}
@@ -467,7 +472,7 @@ TimestampTz get_next_excution_time(char *sql, executor_error_t *ee)
467
472
return ts ;
468
473
}
469
474
470
- int executor_onrollback (job_t * job , executor_error_t * ee )
475
+ int executor_onrollback (MemoryContext mem , job_t * job , executor_error_t * ee )
471
476
{
472
477
int rv ;
473
478
spi_response_t * r ;
@@ -476,7 +481,7 @@ int executor_onrollback(job_t *job, executor_error_t *ee)
476
481
pgstat_report_activity (STATE_RUNNING , "execure onrollback" );
477
482
478
483
START_SPI_SNAP ();
479
- r = execute_spi (CurrentMemoryContext , job -> onrollback );
484
+ r = execute_spi (mem , job -> onrollback );
480
485
if (r -> retval < 0 )
481
486
{
482
487
if (r -> error )
0 commit comments