Skip to content

Commit e7a2430

Browse files
committed
fix potential memory leak
1 parent 2aca12b commit e7a2430

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

libsql-sqlite3/src/vectordiskann.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,11 @@ static void diskAnnNodeFree(DiskAnnNode *pNode){
954954
}
955955

956956
static int diskAnnSearchCtxInit(const DiskAnnIndex *pIndex, DiskAnnSearchCtx *pCtx, const Vector* pQuery, int maxCandidates, int topCandidates, int blobMode){
957+
if( initVectorPair(pIndex->nNodeVectorType, pIndex->nEdgeVectorType, pIndex->nVectorDims, &pCtx->query) != 0 ){
958+
return SQLITE_NOMEM_BKPT;
959+
}
960+
loadVectorPair(&pCtx->query, pQuery);
961+
957962
pCtx->aDistances = sqlite3_malloc(maxCandidates * sizeof(double));
958963
pCtx->aCandidates = sqlite3_malloc(maxCandidates * sizeof(DiskAnnNode*));
959964
pCtx->nCandidates = 0;
@@ -965,10 +970,6 @@ static int diskAnnSearchCtxInit(const DiskAnnIndex *pIndex, DiskAnnSearchCtx *pC
965970
pCtx->visitedList = NULL;
966971
pCtx->nUnvisited = 0;
967972
pCtx->blobMode = blobMode;
968-
if( initVectorPair(pIndex->nNodeVectorType, pIndex->nEdgeVectorType, pIndex->nVectorDims, &pCtx->query) != 0 ){
969-
return SQLITE_NOMEM_BKPT;
970-
}
971-
loadVectorPair(&pCtx->query, pQuery);
972973

973974
if( pCtx->aDistances != NULL && pCtx->aCandidates != NULL && pCtx->aTopDistances != NULL && pCtx->aTopCandidates != NULL ){
974975
return SQLITE_OK;

0 commit comments

Comments
 (0)