diff --git a/pg_store_plans.c b/pg_store_plans.c index a8f01ca..c5fda3f 100644 --- a/pg_store_plans.c +++ b/pg_store_plans.c @@ -409,7 +409,7 @@ _PG_init(void) "Sets the maximum number of plans tracked by pg_store_plans.", NULL, &store_size, - 1000, + 5000, 100, INT_MAX, PGC_POSTMASTER, @@ -471,7 +471,7 @@ _PG_init(void) "Minimum duration to record plan in milliseconds.", NULL, &min_duration, - 0, + 10, 0, INT_MAX, PGC_SUSET, @@ -517,7 +517,7 @@ _PG_init(void) "Log timings.", NULL, &log_timing, - true, + false, PGC_SUSET, 0, NULL, @@ -738,6 +738,15 @@ pgsp_shmem_startup(void) pgver != PGSP_PG_MAJOR_VERSION) goto data_error; + /* check if num is out of range */ + if (num < 0 || num > store_size) + { + ereport(LOG, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("Invalid number of entries in file: %d", num))); + goto data_error; + } + for (i = 0; i < num; i++) { pgspEntry temp; @@ -930,6 +939,10 @@ pgsp_shmem_shutdown(int code, Datum arg) /* Unlink query-texts file; it's not needed while shutdown */ unlink(PGSP_TEXT_FILE); + if (pbuffer){ + free(pbuffer); // or free(pbuffer) + pbuffer = NULL; + } return; error: @@ -940,6 +953,10 @@ pgsp_shmem_shutdown(int code, Datum arg) if (file) FreeFile(file); unlink(PGSP_DUMP_FILE ".tmp"); + if (pbuffer){ + free(pbuffer); // or free(pbuffer) + pbuffer = NULL; + } } @@ -1356,8 +1373,13 @@ pgsp_store(char *plan, queryid_t queryId, e->counters.temp_blks_read += bufusage->temp_blks_read; e->counters.temp_blks_written += bufusage->temp_blks_written; +#if PG_VERSION_NUM >= 170000 /* compatible with version 17 */ + e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->local_blk_read_time); + e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->local_blk_write_time); +#else e->counters.blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_read_time); e->counters.blk_write_time += INSTR_TIME_GET_MILLISEC(bufusage->blk_write_time); +#endif #if PG_VERSION_NUM >= 150000 e->counters.temp_blk_read_time += INSTR_TIME_GET_MILLISEC(bufusage->temp_blk_read_time); @@ -1579,6 +1601,9 @@ pg_store_plans_internal(FunctionCallInfo fcinfo, else pstr = SHMEM_PLAN_PTR(entry); + if (pstr == NULL) + continue; /* Ignore any entries with bogus texts */ + switch (plan_format) { case PLAN_FORMAT_TEXT: @@ -1682,6 +1707,11 @@ pg_store_plans_internal(FunctionCallInfo fcinfo, /* clean up and return the tuplestore */ tuplestore_donestoring(tupstore); + + if (pbuffer){ + free(pbuffer); // or free(pbuffer) + pbuffer = NULL; + } } /* Number of output arguments (columns) for pg_stat_statements_info */