if (fwrite(&pgss->stats, sizeof(pgssGlobalStats), 1, file) != 1)
goto error;
- free(qbuffer);
+ pfree(qbuffer);
qbuffer = NULL;
if (FreeFile(file))
(errcode_for_file_access(),
errmsg("could not write file \"%s\": %m",
PGSS_DUMP_FILE ".tmp")));
- free(qbuffer);
+ if (qbuffer)
+ pfree(qbuffer);
if (file)
FreeFile(file);
unlink(PGSS_DUMP_FILE ".tmp");
pgss->extent != extent ||
pgss->gc_count != gc_count)
{
- free(qbuffer);
+ if (qbuffer)
+ pfree(qbuffer);
qbuffer = qtext_load_file(&qbuffer_size);
}
}
LWLockRelease(pgss->lock);
- free(qbuffer);
+ if (qbuffer)
+ pfree(qbuffer);
}
/* Number of output arguments (columns) for pg_stat_statements_info */
}
/*
- * Read the external query text file into a malloc'd buffer.
+ * Read the external query text file into a palloc'd buffer.
*
* Returns NULL (without throwing an error) if unable to read, eg
* file not there or insufficient memory.
/* Allocate buffer; beware that off_t might be wider than size_t */
if (stat.st_size <= MaxAllocHugeSize)
- buf = (char *) malloc(stat.st_size);
+ buf = (char *) palloc_extended(stat.st_size, MCXT_ALLOC_HUGE | MCXT_ALLOC_NO_OOM);
else
buf = NULL;
if (buf == NULL)
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m",
PGSS_TEXT_FILE)));
- free(buf);
+ pfree(buf);
CloseTransientFile(fd);
return NULL;
}
else
pgss->mean_query_len = ASSUMED_LENGTH_INIT;
- free(qbuffer);
+ pfree(qbuffer);
/*
* OK, count a garbage collection cycle. (Note: even though we have
/* clean up resources */
if (qfile)
FreeFile(qfile);
- free(qbuffer);
+ if (qbuffer)
+ pfree(qbuffer);
/*
* Since the contents of the external file are now uncertain, mark all