From 47979e671c9753d92df0cb4187908c9fb043a96b Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Mon, 21 Feb 2005 10:03:57 +0000 Subject: [PATCH] Fix memory leak for timestamp(with and w/o tz) and indexes --- contrib/btree_gist/btree_time.c | 24 +++++++++++++----------- contrib/btree_gist/btree_ts.c | 14 ++++++++------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/contrib/btree_gist/btree_time.c b/contrib/btree_gist/btree_time.c index cbbe05dc27..ee08a9a51e 100644 --- a/contrib/btree_gist/btree_time.c +++ b/contrib/btree_gist/btree_time.c @@ -30,11 +30,13 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS); Datum gbt_time_same(PG_FUNCTION_ARGS); +#define P_TimeADTGetDatum(x) PointerGetDatum( &(x) ) + static bool gbt_timegt(const void *a, const void *b) { return DatumGetBool( - DirectFunctionCall2(time_gt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b))) + DirectFunctionCall2(time_gt, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b))) ); } @@ -42,7 +44,7 @@ static bool gbt_timege(const void *a, const void *b) { return DatumGetBool( - DirectFunctionCall2(time_ge, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b))) + DirectFunctionCall2(time_ge, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b))) ); } @@ -50,7 +52,7 @@ static bool gbt_timeeq(const void *a, const void *b) { return DatumGetBool( - DirectFunctionCall2(time_eq, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b))) + DirectFunctionCall2(time_eq, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b))) ); } @@ -58,7 +60,7 @@ static bool gbt_timele(const void *a, const void *b) { return DatumGetBool( - DirectFunctionCall2(time_le, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b))) + DirectFunctionCall2(time_le, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b))) ); } @@ -66,7 +68,7 @@ static bool gbt_timelt(const void *a, const void *b) { return DatumGetBool( - DirectFunctionCall2(time_lt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b))) + DirectFunctionCall2(time_lt, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b))) ); } @@ -202,8 +204,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - TimeADTGetDatum(newentry->upper), - TimeADTGetDatum(origentry->upper))); + P_TimeADTGetDatum(newentry->upper), + P_TimeADTGetDatum(origentry->upper))); /* see interval_larger */ res = Max(intr->time + intr->month * (30 * 86400), 0); @@ -211,8 +213,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - TimeADTGetDatum(origentry->lower), - TimeADTGetDatum(newentry->lower))); + P_TimeADTGetDatum(origentry->lower), + P_TimeADTGetDatum(newentry->lower))); /* see interval_larger */ res += Max(intr->time + intr->month * (30 * 86400), 0); @@ -224,8 +226,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS) { intr = DatumGetIntervalP(DirectFunctionCall2( time_mi_time, - TimeADTGetDatum(origentry->upper), - TimeADTGetDatum(origentry->lower))); + P_TimeADTGetDatum(origentry->upper), + P_TimeADTGetDatum(origentry->lower))); *result += FLT_MIN; *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400)))); *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c index f9d801a3fc..aaa0c2e5a4 100644 --- a/contrib/btree_gist/btree_ts.c +++ b/contrib/btree_gist/btree_ts.c @@ -29,6 +29,8 @@ Datum gbt_ts_penalty(PG_FUNCTION_ARGS); Datum gbt_ts_same(PG_FUNCTION_ARGS); +#define P_TimestampGetDatum(x) PointerGetDatum( &(x) ) + static bool gbt_tsgt(const void *a, const void *b) { @@ -231,8 +233,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( timestamp_mi, - TimestampGetDatum(newentry->upper), - TimestampGetDatum(origentry->upper) + P_TimestampGetDatum(newentry->upper), + P_TimestampGetDatum(origentry->upper) )); /* see interval_larger */ @@ -242,8 +244,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS) intr = DatumGetIntervalP(DirectFunctionCall2( timestamp_mi, - TimestampGetDatum(origentry->lower), - TimestampGetDatum(newentry->lower) + P_TimestampGetDatum(origentry->lower), + P_TimestampGetDatum(newentry->lower) )); /* see interval_larger */ @@ -256,8 +258,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS) { intr = DatumGetIntervalP(DirectFunctionCall2( timestamp_mi, - TimestampGetDatum(origentry->upper), - TimestampGetDatum(origentry->lower) + P_TimestampGetDatum(origentry->upper), + P_TimestampGetDatum(origentry->lower) )); *result += FLT_MIN; *result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));