Fix memory leak in ivfrescan

This commit is contained in:
zthhhhh
2026-07-27 18:13:21 +08:00
committed by Andrew Kane
parent c0919bc26a
commit 93a5b4a16d

View File

@@ -282,6 +282,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
so->probes = probes; so->probes = probes;
so->maxProbes = maxProbes; so->maxProbes = maxProbes;
so->dimensions = dimensions; so->dimensions = dimensions;
so->value = PointerGetDatum(NULL);
/* Set support functions */ /* Set support functions */
so->procinfo = index_getprocinfo(index, 1, IVFFLAT_DISTANCE_PROC); so->procinfo = index_getprocinfo(index, 1, IVFFLAT_DISTANCE_PROC);
@@ -340,6 +341,12 @@ ivfflatrescan(IndexScanDesc scan, ScanKey keys, int nkeys, ScanKey orderbys, int
pairingheap_reset(so->listQueue); pairingheap_reset(so->listQueue);
so->listIndex = 0; so->listIndex = 0;
if (so->normprocinfo != NULL && DatumGetPointer(so->value) != NULL)
{
pfree(DatumGetPointer(so->value));
so->value = PointerGetDatum(NULL);
}
if (keys && scan->numberOfKeys > 0) if (keys && scan->numberOfKeys > 0)
memmove(scan->keyData, keys, scan->numberOfKeys * sizeof(ScanKeyData)); memmove(scan->keyData, keys, scan->numberOfKeys * sizeof(ScanKeyData));