Skip to content

Commit 5784b1a

Browse files
author
Vladimir Ershov
committed
fix free error
1 parent e9aa92c commit 5784b1a

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/scheduler_executor.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
162162
int i;
163163
job_t *job;
164164
spi_response_t *r;
165-
MemoryContext old;
166-
MemoryContext mem = init_mem_ctx("executor");
167-
168-
old = MemoryContextSwitchTo(mem);
165+
MemoryContext old, mem;
169166

170167
EE.n = 0;
171168
EE.errors = NULL;
@@ -178,6 +175,9 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
178175
return 0;
179176
}
180177

178+
mem = init_mem_ctx("executor");
179+
old = MemoryContextSwitchTo(mem);
180+
181181
*status = shared->status = SchdExecutorWork;
182182
shared->message[0] = 0;
183183

@@ -191,6 +191,9 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
191191
shared->worker_exit = true;
192192
*status = shared->status = SchdExecutorError;
193193

194+
MemoryContextSwitchTo(old);
195+
MemoryContextDelete(mem);
196+
194197
return -1;
195198
}
196199
current_job_id = job->cron_id;
@@ -211,6 +214,8 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
211214
}
212215
*status = shared->worker_exit = true;
213216
shared->status = SchdExecutorError;
217+
MemoryContextSwitchTo(old);
218+
MemoryContextDelete(mem);
214219
return -2;
215220
}
216221

@@ -257,7 +262,7 @@ int do_one_job(schd_executor_share_t *shared, schd_executor_status_t *status)
257262
destroy_spi_data(r);
258263
ABORT_SPI_SNAP();
259264
SetConfigOption("schedule.transaction_state", "failure", PGC_INTERNAL, PGC_S_SESSION);
260-
executor_onrollback(job, &EE);
265+
executor_onrollback(mem, job, &EE);
261266

262267
break;
263268
}
@@ -467,7 +472,7 @@ TimestampTz get_next_excution_time(char *sql, executor_error_t *ee)
467472
return ts;
468473
}
469474

470-
int executor_onrollback(job_t *job, executor_error_t *ee)
475+
int executor_onrollback(MemoryContext mem, job_t *job, executor_error_t *ee)
471476
{
472477
int rv;
473478
spi_response_t *r;
@@ -476,7 +481,7 @@ int executor_onrollback(job_t *job, executor_error_t *ee)
476481
pgstat_report_activity(STATE_RUNNING, "execure onrollback");
477482

478483
START_SPI_SNAP();
479-
r = execute_spi(CurrentMemoryContext, job->onrollback);
484+
r = execute_spi(mem, job->onrollback);
480485
if(r->retval < 0)
481486
{
482487
if(r->error)

src/scheduler_executor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extern PGDLLEXPORT void executor_worker_main(Datum arg);
6060
job_t *initializeExecutorJob(schd_executor_share_t *data);
6161
void set_shared_message(schd_executor_share_t *shared, executor_error_t *ee);
6262
TimestampTz get_next_excution_time(char *sql, executor_error_t *ee);
63-
int executor_onrollback(job_t *job, executor_error_t *ee);
63+
int executor_onrollback(MemoryContext mem, job_t *job, executor_error_t *ee);
6464
void set_pg_var(bool resulti, executor_error_t *ee);
6565
int push_executor_error(executor_error_t *e, char *fmt, ...) pg_attribute_printf(2, 3);
6666
int set_session_authorization(char *username, char **error);

src/scheduler_spi_utils.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ spi_response_t *__error_spi_resp(MemoryContext ctx, int ret, char *error)
7878
r->retval = ret;
7979
r->types = NULL;
8080
r->rows = NULL;
81+
r->ref = NULL;
8182
r->error = _mcopy_string(ctx, error);
8283

8384
return r;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy