Skip to content

Commit e13ac55

Browse files
committed
Avoid possible crash in contrib/bloom's blendscan().
It's possible to begin and end an indexscan without ever calling amrescan. contrib/bloom, unlike every other index AM, allocated its "scan->opaque" storage at amrescan time, and thus would crash in amendscan if amrescan hadn't been called. We could fix this by putting in a null-pointer check in blendscan, but I see no very good reason why contrib/bloom should march to its own drummer in this respect. Let's move that initialization to blbeginscan instead. Per report from Jeff Janes.
1 parent 7c979c9 commit e13ac55

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

contrib/bloom/blscan.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ IndexScanDesc
2929
blbeginscan(Relation r, int nkeys, int norderbys)
3030
{
3131
IndexScanDesc scan;
32+
BloomScanOpaque so;
3233

3334
scan = RelationGetIndexScan(r, nkeys, norderbys);
3435

36+
so = (BloomScanOpaque) palloc(sizeof(BloomScanOpaqueData));
37+
initBloomState(&so->state, scan->indexRelation);
38+
so->sign = NULL;
39+
40+
scan->opaque = so;
41+
3542
return scan;
3643
}
3744

@@ -42,23 +49,10 @@ void
4249
blrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
4350
ScanKey orderbys, int norderbys)
4451
{
45-
BloomScanOpaque so;
46-
47-
so = (BloomScanOpaque) scan->opaque;
48-
49-
if (so == NULL)
50-
{
51-
/* if called from blbeginscan */
52-
so = (BloomScanOpaque) palloc(sizeof(BloomScanOpaqueData));
53-
initBloomState(&so->state, scan->indexRelation);
54-
scan->opaque = so;
52+
BloomScanOpaque so = (BloomScanOpaque) scan->opaque;
5553

56-
}
57-
else
58-
{
59-
if (so->sign)
60-
pfree(so->sign);
61-
}
54+
if (so->sign)
55+
pfree(so->sign);
6256
so->sign = NULL;
6357

6458
if (scankey && scan->numberOfKeys > 0)

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