Fix memory leak for timestamp(with and w/o tz) and indexes
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 21 Feb 2005 10:03:57 +0000 (10:03 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 21 Feb 2005 10:03:57 +0000 (10:03 +0000)
contrib/btree_gist/btree_time.c
contrib/btree_gist/btree_ts.c

index cbbe05dc271e857a4f4616560c3d91e465de6ca0..ee08a9a51ebb2d8140053f2367ee25e7f32438dc 100644 (file)
@@ -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));
index f9d801a3fc1307f7e73c27a3159d44a4591f6ecb..aaa0c2e5a4bfb63715e7de42901298eb254f44f1 100644 (file)
@@ -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))));