Skip to content

Commit 36ab600

Browse files
author
Neil Conway
committed
Cleanup of GiST extensions in contrib/: now that we always invoke GiST
methods in a short-lived memory context, there is no need for GiST methods to do their own manual (and error-prone) memory management.
1 parent 8758134 commit 36ab600

File tree

16 files changed

+18
-174
lines changed

16 files changed

+18
-174
lines changed

contrib/btree_gist/btree_bit.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
127127
{
128128
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
129129
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
130-
void *qtst = (void *) PG_GETARG_POINTER(1);
131130
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
132131
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
133132
bool retval = FALSE;
@@ -140,11 +139,7 @@ gbt_bit_consistent(PG_FUNCTION_ARGS)
140139
bytea *q = gbt_bit_xfrm((bytea *) query);
141140

142141
retval = gbt_var_consistent(&r, (void *) q, &strategy, FALSE, &tinfo);
143-
pfree(q);
144142
}
145-
146-
if (qtst != query)
147-
pfree(query);
148143
PG_RETURN_BOOL(retval);
149144
}
150145

contrib/btree_gist/btree_bytea.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,12 @@ gbt_bytea_consistent(PG_FUNCTION_ARGS)
9797
{
9898
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
9999
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
100-
void *qtst = (void *) PG_GETARG_POINTER(1);
101100
void *query = (void *) DatumGetByteaP(PG_GETARG_DATUM(1));
102101
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
103-
bool retval = FALSE;
102+
bool retval;
104103
GBT_VARKEY_R r = gbt_var_key_readable(key);
105104

106105
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
107-
108-
if (qtst != query)
109-
pfree(query);
110106
PG_RETURN_BOOL(retval);
111107
}
112108

contrib/btree_gist/btree_numeric.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,12 @@ gbt_numeric_consistent(PG_FUNCTION_ARGS)
9898

9999
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
100100
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
101-
void *qtst = (void *) PG_GETARG_POINTER(1);
102101
void *query = (void *) DatumGetNumeric(PG_GETARG_DATUM(1));
103102
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
104-
bool retval = FALSE;
103+
bool retval;
105104
GBT_VARKEY_R r = gbt_var_key_readable(key);
106105

107106
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
108-
109-
if (qtst != query)
110-
pfree(query);
111107
PG_RETURN_BOOL(retval);
112108
}
113109

@@ -164,8 +160,6 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
164160
PointerGetDatum(uk.lower)
165161
));
166162

167-
pfree(DatumGetPointer(uni));
168-
169163
os = DatumGetNumeric(DirectFunctionCall2(
170164
numeric_sub,
171165
PointerGetDatum(ok.upper),
@@ -178,47 +172,34 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
178172
NumericGetDatum(os)
179173
));
180174

181-
pfree(os);
182-
183175
if (NUMERIC_IS_NAN(us))
184176
{
185-
186177
if (NUMERIC_IS_NAN(os))
187178
*result = 0.0;
188179
else
189180
*result = 1.0;
190-
191181
}
192182
else
193183
{
194-
195184
Numeric nul = DatumGetNumeric(DirectFunctionCall1(int4_numeric, Int32GetDatum(0)));
196185

197186
*result = 0.0;
198187

199188
if (DirectFunctionCall2(numeric_gt, NumericGetDatum(ds), NumericGetDatum(nul)))
200189
{
201-
202190
*result += FLT_MIN;
203191
os = DatumGetNumeric(DirectFunctionCall2(
204192
numeric_div,
205193
NumericGetDatum(ds),
206194
NumericGetDatum(us)
207195
));
208196
*result += (float4) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, NumericGetDatum(os)));
209-
pfree(os);
210-
211197
}
212-
213-
pfree(nul);
214198
}
215199

216200
if (*result > 0)
217201
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
218202

219-
pfree(us);
220-
pfree(ds);
221-
222203
PG_RETURN_POINTER(result);
223204
}
224205

contrib/btree_gist/btree_text.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS)
108108
entry->rel, entry->page,
109109
entry->offset, VARSIZE(DatumGetPointer(d)), TRUE);
110110
retval = gbt_var_compress(&trim, &tinfo);
111-
112-
pfree(DatumGetPointer(d));
113111
}
114112
else
115113
retval = entry;
@@ -124,17 +122,13 @@ gbt_text_consistent(PG_FUNCTION_ARGS)
124122
{
125123
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
126124
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
127-
void *qtst = (void *) PG_GETARG_POINTER(1);
128125
void *query = (void *) DatumGetTextP(PG_GETARG_DATUM(1));
129126
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
130127
bool retval = FALSE;
131128
GBT_VARKEY_R r = gbt_var_key_readable(key);
132129

133130
retval = gbt_var_consistent(&r, query, &strategy, GIST_LEAF(entry), &tinfo);
134131

135-
if (qtst != query)
136-
pfree(query);
137-
138132
PG_RETURN_BOOL(retval);
139133
}
140134

@@ -144,25 +138,17 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS)
144138
{
145139
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
146140
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(entry->key);
147-
void *qtst = (void *) PG_GETARG_POINTER(1);
148141
void *query = (void *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
149142
void *trim = (void *) DatumGetPointer(DirectFunctionCall1(rtrim1, PointerGetDatum(query)));
150143
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
151-
bool retval = FALSE;
144+
bool retval;
152145
GBT_VARKEY_R r = gbt_var_key_readable(key);
153146

154147
retval = gbt_var_consistent(&r, trim, &strategy, GIST_LEAF(entry), &tinfo);
155-
156-
pfree(trim);
157-
158-
if (qtst != query)
159-
pfree(query);
160148
PG_RETURN_BOOL(retval);
161149
}
162150

163151

164-
165-
166152
Datum
167153
gbt_text_union(PG_FUNCTION_ARGS)
168154
{

contrib/btree_gist/btree_time.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
222222

223223
/* see interval_larger */
224224
res = Max(intr->time + intr->month * (30 * 86400), 0);
225-
pfree(intr);
226225

227226
intr = DatumGetIntervalP(DirectFunctionCall2(
228227
time_mi_time,
@@ -231,7 +230,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
231230

232231
/* see interval_larger */
233232
res += Max(intr->time + intr->month * (30 * 86400), 0);
234-
pfree(intr);
235233

236234
*result = 0.0;
237235

@@ -244,7 +242,6 @@ gbt_time_penalty(PG_FUNCTION_ARGS)
244242
*result += FLT_MIN;
245243
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
246244
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
247-
pfree(intr);
248245
}
249246

250247
PG_RETURN_POINTER(result);

contrib/btree_gist/btree_ts.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
226226

227227
#ifdef HAVE_INT64_TIMESTAMP
228228
int64 res;
229-
230229
#else
231230
double res;
232231
#endif
@@ -240,7 +239,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
240239
/* see interval_larger */
241240

242241
res = Max(intr->time + intr->month * (30 * 86400), 0);
243-
pfree(intr);
244242

245243
intr = DatumGetIntervalP(DirectFunctionCall2(
246244
timestamp_mi,
@@ -250,7 +248,6 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
250248

251249
/* see interval_larger */
252250
res += Max(intr->time + intr->month * (30 * 86400), 0);
253-
pfree(intr);
254251

255252
*result = 0.0;
256253

@@ -264,11 +261,9 @@ gbt_ts_penalty(PG_FUNCTION_ARGS)
264261
*result += FLT_MIN;
265262
*result += (float) (res / ((double) (res + intr->time + intr->month * (30 * 86400))));
266263
*result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
267-
pfree(intr);
268264
}
269265

270266
PG_RETURN_POINTER(result);
271-
272267
}
273268

274269

contrib/btree_gist/btree_utils_num.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,5 @@ gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
246246
}
247247
}
248248

249-
pfree(arr);
250-
251249
return v;
252250
}

contrib/btree_gist/btree_utils_var.c

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ Datum gbt_var_decompress(PG_FUNCTION_ARGS);
99
Datum
1010
gbt_var_decompress(PG_FUNCTION_ARGS)
1111
{
12-
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
13-
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
12+
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
13+
GBT_VARKEY *key = (GBT_VARKEY *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
1414

15-
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
16-
{
17-
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
15+
if (key != (GBT_VARKEY *) DatumGetPointer(entry->key))
16+
{
17+
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
1818

19-
gistentryinit(*retval, PointerGetDatum(key),
20-
entry->rel, entry->page,
21-
entry->offset, VARSIZE(key), FALSE);
19+
gistentryinit(*retval, PointerGetDatum(key),
20+
entry->rel, entry->page,
21+
entry->offset, VARSIZE(key), FALSE);
2222

23-
PG_RETURN_POINTER(retval);
24-
}
23+
PG_RETURN_POINTER(retval);
24+
}
2525

26-
PG_RETURN_POINTER(entry);
26+
PG_RETURN_POINTER(entry);
2727
}
2828

2929
/* Returns a better readable representaion of variable key ( sets pointer ) */
@@ -216,7 +216,6 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
216216
GBT_VARKEY_R nr;
217217
GBT_VARKEY_R eo = gbt_var_key_readable(e);
218218

219-
220219
if (eo.lower == eo.upper) /* leaf */
221220
{
222221
tmp = gbt_var_leaf2node(e, tinfo);
@@ -235,31 +234,23 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY * e, const gbtree_vinfo * tinfo)
235234
nr.upper = ro.upper;
236235
nk = gbt_var_key_copy(&nr, TRUE);
237236
}
237+
238238
if ((*tinfo->f_cmp) ((bytea *) ro.upper, (bytea *) eo.upper) < 0)
239239
{
240240
nr.upper = eo.upper;
241241
nr.lower = ro.lower;
242242
nk = gbt_var_key_copy(&nr, TRUE);
243243
}
244+
244245
if (nk)
245-
{
246-
pfree(DatumGetPointer(*u));
247246
*u = PointerGetDatum(nk);
248-
}
249-
250-
251-
252247
}
253248
else
254249
{
255250
nr.lower = eo.lower;
256251
nr.upper = eo.upper;
257252
*u = PointerGetDatum(gbt_var_key_copy(&nr, TRUE));
258253
}
259-
260-
if (tmp && tmp != e)
261-
pfree(tmp);
262-
263254
}
264255

265256

@@ -273,15 +264,12 @@ gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo * tinfo)
273264
if (entry->leafkey)
274265
{
275266
GBT_VARKEY *r = NULL;
276-
bytea *tstd = (bytea *) DatumGetPointer(entry->key); /* toasted */
277-
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); /* untoasted */
267+
bytea *leaf = (bytea *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
278268
GBT_VARKEY_R u;
279269

280270
u.lower = u.upper = leaf;
281271
r = gbt_var_key_copy(&u, FALSE);
282272

283-
if (tstd != leaf)
284-
pfree(leaf);
285273
retval = palloc(sizeof(GISTENTRY));
286274
gistentryinit(*retval, PointerGetDatum(r),
287275
entry->rel, entry->page,
@@ -319,7 +307,6 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo *
319307

320308

321309
/* Truncate (=compress) key */
322-
323310
if (tinfo->trnc)
324311
{
325312
int32 plen;
@@ -328,7 +315,6 @@ gbt_var_union(const GistEntryVector *entryvec, int32 *size, const gbtree_vinfo *
328315
plen = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(out), tinfo);
329316
trc = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(out), plen + 1, tinfo);
330317

331-
pfree(DatumGetPointer(out));
332318
out = PointerGetDatum(trc);
333319
}
334320

@@ -428,17 +414,12 @@ gbt_var_penalty(float *res, const GISTENTRY *o, const GISTENTRY *n, const gbtree
428414
}
429415
dres /= 256.0;
430416
}
431-
pfree(DatumGetPointer(d));
432417

433418
*res += FLT_MIN;
434419
*res += (float) (dres / ((double) (ol + 1)));
435420
*res *= (FLT_MAX / (o->rel->rd_att->natts + 1));
436-
437421
}
438422

439-
if (tmp && tmp != newe)
440-
pfree(tmp);
441-
442423
return res;
443424
}
444425

@@ -524,18 +505,9 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtre
524505
}
525506
}
526507

527-
/* Free strxfrm'ed leafs */
528-
for (i = 0; i < svcntr; i++)
529-
pfree(sv[i]);
530-
531-
if (sv)
532-
pfree(sv);
533-
534508
/* Truncate (=compress) key */
535-
536509
if (tinfo->trnc)
537510
{
538-
539511
int32 ll = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), tinfo);
540512
int32 lr = gbt_var_node_cp_len((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), tinfo);
541513
GBT_VARKEY *dl;
@@ -546,15 +518,10 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtre
546518

547519
dl = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_ldatum), ll, tinfo);
548520
dr = gbt_var_node_truncate((GBT_VARKEY *) DatumGetPointer(v->spl_rdatum), ll, tinfo);
549-
pfree(DatumGetPointer(v->spl_ldatum));
550-
pfree(DatumGetPointer(v->spl_rdatum));
551521
v->spl_ldatum = PointerGetDatum(dl);
552522
v->spl_rdatum = PointerGetDatum(dr);
553-
554523
}
555524

556-
pfree(arr);
557-
558525
return v;
559526
}
560527

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy