This should apply cleanly to cvs tip.

I've not changed any malloc/calloc to palloc. It looks to me that these memory
areas are for the lifetime of the backend and in the interests of not breaking
something that's not broken I left alone.

Note for anyone reading this and wanting it for tsearch-v2-stable (i.e. for 7.3
backend) this patch probably will not apply cleanly to that source. It should
be simple enough to see what's going on and apply the changes by hand if need
be.


-- 
Nigel J. Andrews
Index: contrib/tsearch2/ts_cfg.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/tsearch2/ts_cfg.c,v
retrieving revision 1.3
diff -c -r1.3 ts_cfg.c
*** contrib/tsearch2/ts_cfg.c   4 Aug 2003 00:43:11 -0000       1.3
--- contrib/tsearch2/ts_cfg.c   23 Sep 2003 23:43:44 -0000
***************
*** 112,117 ****
--- 110,118 ----
  
                cfg->map[lexid].len = ARRNELEMS(a);
                cfg->map[lexid].dict_id = (Datum *) malloc(sizeof(Datum) * 
cfg->map[lexid].len);
+               if (!cfg->map[lexid].dict_id)
+                               ts_error(ERROR, "No memory");
+ 
                memset(cfg->map[lexid].dict_id, 0, sizeof(Datum) * 
cfg->map[lexid].len);
                ptr = (text *) ARR_DATA_PTR(a);
                oldcontext = MemoryContextSwitchTo(TopMemoryContext);
Index: contrib/tsearch2/snowball/api.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/tsearch2/snowball/api.c,v
retrieving revision 1.3
diff -c -r1.3 api.c
*** contrib/tsearch2/snowball/api.c     4 Aug 2003 00:43:11 -0000       1.3
--- contrib/tsearch2/snowball/api.c     23 Sep 2003 23:43:55 -0000
***************
*** 6,44 ****
  SN_create_env(int S_size, int I_size, int B_size)
  {
        struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
  
        z->p = create_s();
!       if (S_size)
        {
!               z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
                {
                        int                     i;
  
                        for (i = 0; i < S_size; i++)
!                               z->S[i] = create_s();
                }
!               z->S_size = S_size;
        }
  
!       if (I_size)
        {
                z->I = (int *) calloc(I_size, sizeof(int));
!               z->I_size = I_size;
        }
  
!       if (B_size)
        {
                z->B = (symbol *) calloc(B_size, sizeof(symbol));
!               z->B_size = B_size;
        }
  
        return z;
  }
  
  extern void
  SN_close_env(struct SN_env * z)
  {
!       if (z->S_size)
        {
                {
                        int                     i;
--- 6,68 ----
  SN_create_env(int S_size, int I_size, int B_size)
  {
        struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
+       struct SN_env *z2 = z;
+ 
+       if (!z)
+               return z;
  
        z->p = create_s();
!       if (!z->p)
!               z = NULL;
! 
!       if (z && S_size)
        {
!               if ((z->S = (symbol * *) calloc(S_size, sizeof(symbol *))))
                {
                        int                     i;
  
                        for (i = 0; i < S_size; i++)
!                       {
!                               if (!(z->S[i] = create_s()))
!                               {
!                                       z = NULL;
!                                       break;
!                               }
!                       }
!                       z2->S_size = i;
                }
!               else
!                       z = NULL;
        }
  
!       if (z && I_size)
        {
                z->I = (int *) calloc(I_size, sizeof(int));
!               if (z->I)
!                       z->I_size = I_size;
!               else
!                       z = NULL;
        }
  
!       if (z && B_size)
        {
                z->B = (symbol *) calloc(B_size, sizeof(symbol));
!               if (z->B)
!                       z->B_size = B_size;
!               else
!                       z = NULL;
        }
  
+       if (!z)
+               SN_close_env(z2);
+ 
        return z;
  }
  
  extern void
  SN_close_env(struct SN_env * z)
  {
!       if (z->S && z->S_size)
        {
                {
                        int                     i;
Index: contrib/tsearch2/snowball/utilities.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/contrib/tsearch2/snowball/utilities.c,v
retrieving revision 1.3
diff -c -r1.3 utilities.c
*** contrib/tsearch2/snowball/utilities.c       8 Aug 2003 21:41:24 -0000       1.3
--- contrib/tsearch2/snowball/utilities.c       23 Sep 2003 23:43:57 -0000
***************
*** 14,19 ****
--- 14,21 ----
  {
        symbol     *p = (symbol *) (HEAD + (char *) malloc(HEAD + (CREATE_SIZE + 1) * 
sizeof(symbol)));
  
+       if (p == (symbol *) (HEAD))
+               return NULL;
        CAPACITY(p) = CREATE_SIZE;
        SET_SIZE(p, CREATE_SIZE);
        return p;
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to