Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c8a267

Browse files
committed
Fix freeing old values in index_store_float8_orderby_distances()
6cae9d2 has added an error in freeing old values inindex_store_float8_orderby_distances() function. It looks for old value inscan->xs_orderbynulls[i] after setting a new value there.This commit fixes that. Also it removes short-circuit in handlingdistances == NULL situation. Now distances == NULL will be treated the sameway as array with all null distances. That is, previous values will be freedif any.Reported-by: Tom Lane, Nikita GlukhovDiscussion:https://postgr.es/m/CAPpHfdu2wcoAVAm3Ek66rP%3Duo_C-D84%2B%2Buf1VEcbyi_caBXWCA%40mail.gmail.comDiscussion:https://postgr.es/m/426580d3-a668-b9d1-7b8e-f74d1a6524e0%40postgrespro.ruBackpatch-through: 12
1 parent6cae9d2 commit8c8a267

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

‎src/backend/access/index/indexam.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -852,37 +852,29 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
852852
{
853853
inti;
854854

855-
scan->xs_recheckorderby=recheckOrderBy;
856-
857-
if (!distances)
858-
{
859-
Assert(!scan->xs_recheckorderby);
860-
861-
for (i=0;i<scan->numberOfOrderBys;i++)
862-
{
863-
scan->xs_orderbyvals[i]= (Datum)0;
864-
scan->xs_orderbynulls[i]= true;
865-
}
855+
Assert(distances|| !recheckOrderBy);
866856

867-
return;
868-
}
857+
scan->xs_recheckorderby=recheckOrderBy;
869858

870859
for (i=0;i<scan->numberOfOrderBys;i++)
871860
{
872-
scan->xs_orderbynulls[i]=distances[i].isnull;
873-
874-
if (scan->xs_orderbynulls[i])
875-
scan->xs_orderbyvals[i]= (Datum)0;
876-
877861
if (orderByTypes[i]==FLOAT8OID)
878862
{
879863
#ifndefUSE_FLOAT8_BYVAL
880864
/* must free any old value to avoid memory leakage */
881865
if (!scan->xs_orderbynulls[i])
882866
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
883867
#endif
884-
if (!scan->xs_orderbynulls[i])
868+
if (distances&& !distances[i].isnull)
869+
{
885870
scan->xs_orderbyvals[i]=Float8GetDatum(distances[i].value);
871+
scan->xs_orderbynulls[i]= false;
872+
}
873+
else
874+
{
875+
scan->xs_orderbyvals[i]= (Datum)0;
876+
scan->xs_orderbynulls[i]= true;
877+
}
886878
}
887879
elseif (orderByTypes[i]==FLOAT4OID)
888880
{
@@ -892,8 +884,16 @@ index_store_float8_orderby_distances(IndexScanDesc scan, Oid *orderByTypes,
892884
if (!scan->xs_orderbynulls[i])
893885
pfree(DatumGetPointer(scan->xs_orderbyvals[i]));
894886
#endif
895-
if (!scan->xs_orderbynulls[i])
887+
if (distances&& !distances[i].isnull)
888+
{
896889
scan->xs_orderbyvals[i]=Float4GetDatum((float4)distances[i].value);
890+
scan->xs_orderbynulls[i]= false;
891+
}
892+
else
893+
{
894+
scan->xs_orderbyvals[i]= (Datum)0;
895+
scan->xs_orderbynulls[i]= true;
896+
}
897897
}
898898
else
899899
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp