From a109f5e6972d156422cb9ee969bd4938b655e4c5 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 2 Dec 2024 10:35:37 +0100 Subject: [PATCH v2 02/11] replication parser: Use palloc() instead of malloc() for flex --- src/backend/replication/repl_scanner.l | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/backend/replication/repl_scanner.l b/src/backend/replication/repl_scanner.l index 32eedb812fe..be633a6e826 100644 --- a/src/backend/replication/repl_scanner.l +++ b/src/backend/replication/repl_scanner.l @@ -61,6 +61,9 @@ static void addlitchar(unsigned char ychar); %option noinput %option nounput %option noyywrap +%option noyyalloc +%option noyyrealloc +%option noyyfree %option warn %option prefix="replication_yy" @@ -313,3 +316,30 @@ replication_scanner_is_replication_command(yyscan_t yyscanner) return false; } } + +/* + * Interface functions to make flex use palloc() instead of malloc(). + * It'd be better to make these static, but flex insists otherwise. + */ + +void * +yyalloc(yy_size_t size, yyscan_t yyscanner) +{ + return palloc(size); +} + +void * +yyrealloc(void *ptr, yy_size_t size, yyscan_t yyscanner) +{ + if (ptr) + return repalloc(ptr, size); + else + return palloc(size); +} + +void +yyfree(void *ptr, yyscan_t yyscanner) +{ + if (ptr) + pfree(ptr); +} -- 2.47.1