Skip to content

Commit 5cf0355

Browse files
committed
btree_gist: Fix memory allocation formula
This change has been suggested by the two authors listed in this commit, both of them providing an incomplete solution (David's formula relied on a "bytea *", while Bertrand's did not use palloc_array()). The solution provided in this commit uses GBT_VARKEY instead of the inconsistent bytea for the allocation size, with a palloc_array(). The change related to Vsrt is one I am flipping to a more consistent style, in passing. Author: David Geier <geidav.pg@gmail.com> Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/ad0748d4-3080-436e-b0bc-ac8f86a3466a@gmail.com Discussion: https://postgr.es/m/aTrG3Fi4APtfiCvQ@ip-10-97-1-34.eu-west-3.compute.internal
1 parent 167cb26 commit 5cf0355

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contrib/btree_gist/btree_utils_var.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
467467
GBT_VARKEY **sv = NULL;
468468
gbt_vsrt_arg varg;
469469

470-
arr = (Vsrt *) palloc((maxoff + 1) * sizeof(Vsrt));
470+
arr = palloc_array(Vsrt, maxoff + 1);
471471
nbytes = (maxoff + 2) * sizeof(OffsetNumber);
472472
v->spl_left = (OffsetNumber *) palloc(nbytes);
473473
v->spl_right = (OffsetNumber *) palloc(nbytes);
@@ -476,7 +476,7 @@ gbt_var_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v,
476476
v->spl_nleft = 0;
477477
v->spl_nright = 0;
478478

479-
sv = palloc(sizeof(bytea *) * (maxoff + 1));
479+
sv = palloc_array(GBT_VARKEY *, maxoff + 1);
480480

481481
/* Sort entries */
482482

0 commit comments

Comments
 (0)