Fix bug with multiple evaluation of tsearch2 compatibility trigger, trigger
authorTeodor Sigaev <teodor@sigaev.ru>
Wed, 28 Jan 2009 18:31:32 +0000 (18:31 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Wed, 28 Jan 2009 18:31:32 +0000 (18:31 +0000)
data should be restored.
Backpatch only for 8.3 because previous versions haven't such layer.

contrib/tsearch2/tsearch2.c

index 4e127264eb9e7d6a32a5c9da5d5098ab74ec3418..db59331ab7e16d41ff1d7801a54720c555d6ec9c 100644 (file)
@@ -367,8 +367,10 @@ tsa_tsearch2(PG_FUNCTION_ARGS)
 {
        TriggerData *trigdata;
        Trigger    *trigger;
-       char      **tgargs;
+       char      **tgargs, 
+                         **tgargs_old;
        int                     i;
+       Datum           res;
 
        /* Check call context */
        if (!CALLED_AS_TRIGGER(fcinfo))         /* internal error */
@@ -388,10 +390,20 @@ tsa_tsearch2(PG_FUNCTION_ARGS)
 
        tgargs[1] = pstrdup(GetConfigOptionByName("default_text_search_config",
                                                                                          NULL));
+       tgargs_old = trigger->tgargs;
        trigger->tgargs = tgargs;
        trigger->tgnargs++;
 
-       return tsvector_update_trigger_byid(fcinfo);
+       res = tsvector_update_trigger_byid(fcinfo);
+
+       /* restore old trigger data */
+       trigger->tgargs = tgargs_old;
+       trigger->tgnargs--;
+
+       pfree(tgargs[1]);
+       pfree(tgargs);
+
+       return res;
 }