From 1a5dc2f4dfbf72c772e3797ce02c5cbc7310fa8f Mon Sep 17 00:00:00 2001 From: mj Date: Fri, 28 Sep 2001 23:38:34 +0000 Subject: [PATCH] Removed two memory holes that resulted from missing free() calls. --- dbscripts/dupetrigger/INSTALL | 5 ++++- dbscripts/dupetrigger/dupetrigger.c | 10 ++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dbscripts/dupetrigger/INSTALL b/dbscripts/dupetrigger/INSTALL index 331a3edd..2e62c385 100755 --- a/dbscripts/dupetrigger/INSTALL +++ b/dbscripts/dupetrigger/INSTALL @@ -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.) diff --git a/dbscripts/dupetrigger/dupetrigger.c b/dbscripts/dupetrigger/dupetrigger.c index 1b0993b8..16831035 100755 --- a/dbscripts/dupetrigger/dupetrigger.c +++ b/dbscripts/dupetrigger/dupetrigger.c @@ -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); } -- 2.11.0