diff --git a/src/backend/bootstrap/bootscanner.l b/src/backend/bootstrap/bootscanner.l
index 22fd7f483d78637d7b1d16a2565aa0c4de6f0a90..a7254994ec846702703a54e295e96b95dd78ac37 100644
--- a/src/backend/bootstrap/bootscanner.l
+++ b/src/backend/bootstrap/bootscanner.l
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.14 1999/07/17 20:16:47 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.15 1999/09/11 22:26:41 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -98,12 +98,17 @@ insert			{ return(INSERT_TUPLE); }
 					return(ID);
 				}
 {id}			{
-					yylval.ival = EnterString(scanstr((char*)yytext));
+					char   *newid = scanstr((char*)yytext);
+					yylval.ival = EnterString(newid);
+					pfree(newid);
 					return(ID);
 				}
 {sid}			{
+					char   *newid;
 					yytext[strlen(yytext)-1] = '\0'; /* strip off quotes */
-					yylval.ival = EnterString(scanstr((char*)yytext+1));
+					newid = scanstr((char*)yytext+1);
+					yylval.ival = EnterString(newid);
+					pfree(newid);
 					yytext[strlen(yytext)] = '"'; /* restore quotes */
 					return(ID);
 				}
diff --git a/src/backend/parser/scan.l b/src/backend/parser/scan.l
index ece71b489fdef0f5e6ebb14e0fd1648fcdaa2fd7..011676de1d7b24f47906ca960c5a16c49b5aad7a 100644
--- a/src/backend/parser/scan.l
+++ b/src/backend/parser/scan.l
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.53 1999/09/07 00:13:27 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.54 1999/09/11 22:26:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -246,7 +246,7 @@ other			.
 				}
 <xq>{xqstop}	{
 					BEGIN(INITIAL);
-					yylval.str = pstrdup(scanstr(literal));
+					yylval.str = scanstr(literal);
 					return SCONST;
 				}
 <xq>{xqdouble}	|
diff --git a/src/backend/parser/scansup.c b/src/backend/parser/scansup.c
index df3ea1d931aff68f8ed580b0b2246a999446232c..4e15bd240952d11942cd21358c078dfd36a63191 100644
--- a/src/backend/parser/scansup.c
+++ b/src/backend/parser/scansup.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.16 1999/07/17 20:17:27 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/parser/scansup.c,v 1.17 1999/09/11 22:26:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -25,24 +25,26 @@
  * if the string passed in has escaped codes, map the escape codes to actual
  * chars
  *
- * the string returned is a pointer to static storage and should NOT
- * be freed by the caller.
+ * the string returned is palloc'd and should eventually be pfree'd by the
+ * caller!
  * ----------------
  */
 
 char *
 scanstr(char *s)
 {
-	static char newStr[MAX_PARSE_BUFFER];
+	char	   *newStr;
 	int			len,
 				i,
 				j;
 
 	if (s == NULL || s[0] == '\0')
-		return s;
+		return pstrdup("");
 
 	len = strlen(s);
 
+	newStr = palloc(len+1);		/* string cannot get longer */
+
 	for (i = 0, j = 0; i < len; i++)
 	{
 		if (s[i] == '\'')
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index f583a60294b8ac834814b8f5863fd904b28aff59..211183badf15afbdfec848ccd699344332262fb7 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -239,7 +239,7 @@ cppline		{space}*#.*(\\{space}*\n)*\n*
 				}
 <xq>{xqstop}	{
 					BEGIN(SQL);
-					/* yylval.str = mm_strdup(scanstr(literal));*/
+					/* yylval.str = scanstr(literal); */
 					yylval.str = mm_strdup(literal);
 					return SCONST;
 				}
@@ -601,7 +601,7 @@ cppline		{space}*#.*(\\{space}*\n)*\n*
                                      if (strcmp(old, ptr->old) == 0)
                                      {
 					free(ptr->new);
-					/* ptr->new = mm_strdup(scanstr(literal));*/
+					/* ptr->new = scanstr(literal); */
 					ptr->new = mm_strdup(literal);
                                      }
                                 }
@@ -611,7 +611,7 @@ cppline		{space}*#.*(\\{space}*\n)*\n*
 
                                         /* initial definition */
                                         this->old = old;
-                                        /* this->new = mm_strdup(scanstr(literal));*/
+                                        /* this->new = scanstr(literal); */
                                         this->new = mm_strdup(literal);
 					this->next = defines;
 					defines = this;