diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 0af6142..62c4b63 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -62,6 +62,11 @@
 #include "utils/numeric.h"
 #include "utils/xml.h"
 
+/*
+ * bison does not re-use buffers, so we can order it to use palloc/pfree.
+ */
+#define YYMALLOC palloc
+#define YYFREE   pfree
 
 /* Location tracking support --- simpler than bison's default */
 #define YYLLOC_DEFAULT(Current, Rhs, N) \
