Avoid core dump on empty thesaurus dictionary.
authorTom Lane <[email protected]>
Mon, 30 Nov 2009 16:38:31 +0000 (16:38 +0000)
committerTom Lane <[email protected]>
Mon, 30 Nov 2009 16:38:31 +0000 (16:38 +0000)
Per report from Robert Gravsjö.

src/backend/tsearch/dict_thesaurus.c

index 5c0b0f62e313160ce52c8dc99ce818204f090945..3d6a807dbc04d430e7a1f091ae97191173a1b456 100644 (file)
@@ -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;