Skip to content

Commit 7f12995

Browse files
committed
Detoast query in g_intbig_consistent and copy query in g_int_consistent
1 parent ef524d1 commit 7f12995

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

contrib/intarray/_int_gist.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ Datum
3232
g_int_consistent(PG_FUNCTION_ARGS)
3333
{
3434
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
35-
ArrayType *query = (ArrayType *) PG_GETARG_POINTER(1);
35+
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(1));
3636
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
3737
bool retval;
3838

39-
if (strategy == BooleanSearchStrategy)
40-
PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
39+
if (strategy == BooleanSearchStrategy) {
40+
retval = execconsistent((QUERYTYPE *) query,
4141
(ArrayType *) DatumGetPointer(entry->key),
42-
GIST_LEAF(entry)));
42+
GIST_LEAF(entry));
43+
44+
pfree( query );
45+
PG_RETURN_BOOL(retval);
46+
}
4347

44-
/* XXX are we sure it's safe to scribble on the query object here? */
45-
/* XXX what about toasted input? */
4648
/* sort query for fast search, key is already sorted */
4749
CHECKARRVALID(query);
4850
if (ARRISVOID(query))
@@ -82,6 +84,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
8284
default:
8385
retval = FALSE;
8486
}
87+
pfree( query );
8588
PG_RETURN_BOOL(retval);
8689
}
8790

contrib/intarray/_intbig_gist.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ Datum
497497
g_intbig_consistent(PG_FUNCTION_ARGS)
498498
{
499499
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
500-
ArrayType *query = (ArrayType *) PG_GETARG_POINTER(1);
500+
ArrayType *query = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
501501
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
502502
bool retval;
503503

@@ -506,12 +506,13 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
506506

507507
if (strategy == BooleanSearchStrategy)
508508
{
509-
PG_RETURN_BOOL(signconsistent((QUERYTYPE *) query,
509+
retval =signconsistent((QUERYTYPE *) query,
510510
GETSIGN(DatumGetPointer(entry->key)),
511-
false));
511+
false);
512+
PG_FREE_IF_COPY( query, 1 );
513+
return retval;
512514
}
513515

514-
/* XXX what about toasted input? */
515516
CHECKARRVALID(query);
516517
if (ARRISVOID(query))
517518
return FALSE;
@@ -597,5 +598,6 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
597598
default:
598599
retval = FALSE;
599600
}
601+
PG_FREE_IF_COPY( query, 1 );
600602
PG_RETURN_BOOL(retval);
601603
}

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