Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 47979e6

Browse files
committed
Fix memory leak for timestamp(with and w/o tz) and indexes
1 parent 70b64cf commit 47979e6

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

contrib/btree_gist/btree_time.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,45 @@ Datum gbt_time_penalty(PG_FUNCTION_ARGS);
3030
Datum gbt_time_same(PG_FUNCTION_ARGS);
3131

3232

33+
#define P_TimeADTGetDatum(x) PointerGetDatum( &(x) )
34+
3335
static bool
3436
gbt_timegt(const void *a, const void *b)
3537
{
3638
return DatumGetBool(
37-
DirectFunctionCall2(time_gt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
39+
DirectFunctionCall2(time_gt, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b)))
3840
);
3941
}
4042

4143
static bool
4244
gbt_timege(const void *a, const void *b)
4345
{
4446
return DatumGetBool(
45-
DirectFunctionCall2(time_ge, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
47+
DirectFunctionCall2(time_ge, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b)))
4648
);
4749
}
4850

4951
static bool
5052
gbt_timeeq(const void *a, const void *b)
5153
{
5254
return DatumGetBool(
53-
DirectFunctionCall2(time_eq, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
55+
DirectFunctionCall2(time_eq, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b)))
5456
);
5557
}
5658

5759
static bool
5860
gbt_timele(const void *a, const void *b)
5961
{
6062
return DatumGetBool(
61-
DirectFunctionCall2(time_le, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
63+
DirectFunctionCall2(time_le, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b)))
6264
);
6365
}
6466

6567
static bool
6668
gbt_timelt(const void *a, const void *b)
6769
{
6870
return DatumGetBool(
69-
DirectFunctionCall2(time_lt, TimeADTGetDatum(*((TimeADT *) a)), TimeADTGetDatum(*((TimeADT *) b)))
71+
DirectFunctionCall2(time_lt, P_TimeADTGetDatum(*((TimeADT *) a)), P_TimeADTGetDatum(*((TimeADT *) b)))
7072
);
7173
}
7274

@@ -202,17 +204,17 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
202204

203205
intr = DatumGetIntervalP(DirectFunctionCall2(
204206
time_mi_time,
205-
TimeADTGetDatum(newentry->upper),
206-
TimeADTGetDatum(origentry->upper)));
207+
P_TimeADTGetDatum(newentry->upper),
208+
P_TimeADTGetDatum(origentry->upper)));
207209

208210
/* see interval_larger */
209211
res = Max(intr->time + intr->month * (30 * 86400), 0);
210212
pfree(intr);
211213

212214
intr = DatumGetIntervalP(DirectFunctionCall2(
213215
time_mi_time,
214-
TimeADTGetDatum(origentry->lower),
215-
TimeADTGetDatum(newentry->lower)));
216+
P_TimeADTGetDatum(origentry->lower),
217+
P_TimeADTGetDatum(newentry->lower)));
216218

217219
/* see interval_larger */
218220
res += Max(intr->time + intr->month * (30 * 86400), 0);
@@ -224,8 +226,8 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
224226
{
225227
intr = DatumGetIntervalP(DirectFunctionCall2(
226228
time_mi_time,
227-
TimeADTGetDatum(origentry->upper),
228-
TimeADTGetDatum(origentry->lower)));
229+
P_TimeADTGetDatum(origentry->upper),
230+
P_TimeADTGetDatum(origentry->lower)));
229231
*result += FLT_MIN;
230232
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
231233
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));

contrib/btree_gist/btree_ts.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Datum gbt_ts_penalty(PG_FUNCTION_ARGS);
2929
Datum gbt_ts_same(PG_FUNCTION_ARGS);
3030

3131

32+
#define P_TimestampGetDatum(x) PointerGetDatum( &(x) )
33+
3234
static bool
3335
gbt_tsgt(const void *a, const void *b)
3436
{
@@ -231,8 +233,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
231233

232234
intr = DatumGetIntervalP(DirectFunctionCall2(
233235
timestamp_mi,
234-
TimestampGetDatum(newentry->upper),
235-
TimestampGetDatum(origentry->upper)
236+
P_TimestampGetDatum(newentry->upper),
237+
P_TimestampGetDatum(origentry->upper)
236238
));
237239

238240
/* see interval_larger */
@@ -242,8 +244,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
242244

243245
intr = DatumGetIntervalP(DirectFunctionCall2(
244246
timestamp_mi,
245-
TimestampGetDatum(origentry->lower),
246-
TimestampGetDatum(newentry->lower)
247+
P_TimestampGetDatum(origentry->lower),
248+
P_TimestampGetDatum(newentry->lower)
247249
));
248250

249251
/* see interval_larger */
@@ -256,8 +258,8 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
256258
{
257259
intr = DatumGetIntervalP(DirectFunctionCall2(
258260
timestamp_mi,
259-
TimestampGetDatum(origentry->upper),
260-
TimestampGetDatum(origentry->lower)
261+
P_TimestampGetDatum(origentry->upper),
262+
P_TimestampGetDatum(origentry->lower)
261263
));
262264
*result += FLT_MIN;
263265
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));

0 commit comments

Comments
 (0)