]> granicus.if.org Git - postgresql/commitdiff
I've not changed any malloc/calloc to palloc. It looks to me that these memory
authorBruce Momjian <bruce@momjian.us>
Mon, 29 Sep 2003 18:54:38 +0000 (18:54 +0000)
committerBruce Momjian <bruce@momjian.us>
Mon, 29 Sep 2003 18:54:38 +0000 (18:54 +0000)
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

contrib/tsearch2/snowball/api.c
contrib/tsearch2/snowball/utilities.c
contrib/tsearch2/ts_cfg.c

index 5cbf37d73bf123ab7f4f5dac0fa716fa5b3772d6..426341a360b41e60990676d984533618f9275cb9 100644 (file)
@@ -6,39 +6,63 @@ extern struct SN_env *
 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 (S_size)
+       if (!z->p)
+               z = NULL;
+
+       if (z && S_size)
        {
-               z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
+               if ((z->S = (symbol * *) calloc(S_size, sizeof(symbol *))))
                {
                        int                     i;
 
                        for (i = 0; i < S_size; i++)
-                               z->S[i] = create_s();
+                       {
+                               if (!(z->S[i] = create_s()))
+                               {
+                                       z = NULL;
+                                       break;
+                               }
+                       }
+                       z2->S_size = i;
                }
-               z->S_size = S_size;
+               else
+                       z = NULL;
        }
 
-       if (I_size)
+       if (z && I_size)
        {
                z->I = (int *) calloc(I_size, sizeof(int));
-               z->I_size = I_size;
+               if (z->I)
+                       z->I_size = I_size;
+               else
+                       z = NULL;
        }
 
-       if (B_size)
+       if (z && B_size)
        {
                z->B = (symbol *) calloc(B_size, sizeof(symbol));
-               z->B_size = B_size;
+               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_size)
+       if (z->S && z->S_size)
        {
                {
                        int                     i;
index 4ec71dc7934f78d8f81b2ab3c6e3badd3bb17264..4d031f1c9c11d3e9683b1317f69edc1dfcaf2b7f 100644 (file)
@@ -14,6 +14,8 @@ create_s(void)
 {
        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;
index 1d3ca86a095aecc3504eeb0f34068eac1e91884a..6ff25b2b166de0f8ce04e79bb4aa062c86258a25 100644 (file)
@@ -112,6 +112,9 @@ init_cfg(Oid id, TSCfgInfo * cfg)
 
                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);