Removed two memory holes that resulted from missing free() calls.
authormj <mj>
Fri, 28 Sep 2001 23:38:34 +0000 (23:38 +0000)
committermj <mj>
Fri, 28 Sep 2001 23:38:34 +0000 (23:38 +0000)
dbscripts/dupetrigger/INSTALL
dbscripts/dupetrigger/dupetrigger.c

index 331a3ed..2e62c38 100755 (executable)
@@ -6,7 +6,10 @@ To install the trigger do the following:
 (and change pathnames and PGVERSION if neccessary).
 
 # make
-(This makes the trigger binary and places it in /tmp with permissions 644)
+(This makes the trigger binary and places it in INSTALLDIR with permissions 644)
+
+# edit postgresql.script
+(And change the path to dupetrigger.so to INSTALLDIR)
 
 # psql -U postgres Mir < postgresql.script
 (This installs the the trigger binary and creates a new trigger.)
index 1b0993b..1683103 100755 (executable)
@@ -131,7 +131,7 @@ Datum dupecheck(void)
        bool            isnull,
                                debug_on;
        int                     ret = 0, i, fnumber;
-       long rowstrlen = 0,
+       u_long rowstrlen = 0,
                crc;
        char **items, // will point to a malloc'ed array
                *rowstring,
@@ -246,6 +246,7 @@ Datum dupecheck(void)
        {
                // Big problem
                free(items);
+               free(rowstring);
                SPI_finish();
                return PointerGetDatum(NULL);
        }
@@ -258,9 +259,7 @@ Datum dupecheck(void)
        if ((ret == SPI_OK_SELECT) && (num > 0) && !(TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)))
        {
                elog(NOTICE, "dupecheck: UBD in %s detected, dupe dropped", relation);
-               free(items);
-               SPI_finish();
-               return PointerGetDatum(NULL);
+               rettuple = NULL; // reject operation
        }
        else
        {
@@ -279,6 +278,9 @@ Datum dupecheck(void)
                rettuple = SPI_modifytuple(trigdata->tg_relation, rettuple, 1, &attnum, &value, &nulls);
        }
 
+       free(items);
+       free(rowstring);
+       free(query);
        SPI_finish();
        return PointerGetDatum(rettuple);
 }