From 908854209b142b5c69b54ac929200ae9746e439a Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 30 Nov 2009 16:38:31 +0000
Subject: [PATCH] =?UTF-8?q?Avoid=20core=20dump=20on=20empty=20thesaurus=20?=
 =?UTF-8?q?dictionary.=20Per=20report=20from=20Robert=20Gravsj=C3=B6.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/backend/tsearch/dict_thesaurus.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/tsearch/dict_thesaurus.c b/src/backend/tsearch/dict_thesaurus.c
index 4befc72989d..cfa8be8d12d 100644
--- a/src/backend/tsearch/dict_thesaurus.c
+++ b/src/backend/tsearch/dict_thesaurus.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.14 2009/07/16 06:33:44 petere Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.15 2009/11/30 16:38:31 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -57,8 +57,8 @@ typedef struct
 
 	/* Array to search lexeme by exact match */
 	TheLexeme  *wrds;
-	int			nwrds;
-	int			ntwrds;
+	int			nwrds;			/* current number of words */
+	int			ntwrds;			/* allocated array length */
 
 	/*
 	 * Storage of substituted result, n-th element is for n-th expression
@@ -298,7 +298,6 @@ thesaurusRead(char *filename, DictThesaurus *d)
 static TheLexeme *
 addCompiledLexeme(TheLexeme *newwrds, int *nnw, int *tnm, TSLexeme *lexeme, LexemeInfo *src, uint16 tnvariant)
 {
-
 	if (*nnw >= *tnm)
 	{
 		*tnm *= 2;
@@ -453,7 +452,8 @@ compileTheLexeme(DictThesaurus *d)
 		pfree(d->wrds[i].entries);
 	}
 
-	pfree(d->wrds);
+	if (d->wrds)
+		pfree(d->wrds);
 	d->wrds = newwrds;
 	d->nwrds = nnw;
 	d->ntwrds = tnm;
-- 
GitLab