8000 Remove unnecessary pfree() in g_intbig_compress(). · postgres/postgres@9f70f6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f70f6d

Browse files
committed
Remove unnecessary pfree() in g_intbig_compress().
GiST compress functions (like all GiST opclass functions) are supposed to be called in short-lived memory contexts, so that minor memory leaks in them are not of concern, and indeed explicit pfree's are likely slightly counterproductive. But this one in g_intbig_compress() is more than slightly counterproductive, because it's guarded by "if (in != DatumGetArrayTypeP(entry->key))" which means that if this test succeeds, we've detoasted the datum twice. (And to add insult to injury, the extra detoast result is leaked.) Let's just drop the whole stanza, relying on the GiST temporary context mechanism to clean up in good time. The analogous bit in g_int_compress() is if (r != (ArrayType *) DatumGetPointer(entry->key)) pfree(r); which doesn't have the gratuitous-detoast problem so I left it alone. Perhaps there is a case for removing unnecessary pfree's more widely, but I'm not sure if it's worth the code churn. The potential extra decompress seems expensive enough to justify calling this a (minor) performance bug and back-patching. Konstantin Knizhnik, Matthias van de Meent, Tom Lane Discussion: https://postgr.es/m/CAEze2Wi86=DxErfvf+SCB2UKmU2amKOF60BKuJOX=w-RojRn0A@mail.gmail.com
1 parent 671bf1c commit 9f70f6d

File tree

1 file changed

+0
-3
lines changed

1 file changed

+0
-3
lines changed

contrib/intarray/_intbig_gist.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ g_intbig_compress(PG_FUNCTION_ARGS)
170170
entry->rel, entry->page,
171171
entry->offset, false);
172172

173-
if (in != DatumGetArrayTypeP(entry->key))
174-
pfree(in);
175-
176173
PG_RETURN_POINTER(retval);
177174
}
178175
else if (!ISALLTRUE(DatumGetPointer(entry->key)))

0 commit comments

Comments
 (0)
0