Skip to content

Commit 1f20a5b

Browse files
committed
Avoid passing exact same LeanVecMatricesType args
1 parent a65a641 commit 1f20a5b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

bindings/cpp/src/training_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ struct LeanVecTrainingDataImpl {
7474
auto matrix = svs::leanvec::compute_leanvec_matrix<svs::Dynamic, svs::Dynamic>(
7575
data, means, threadpool, svs::lib::MaybeStatic<svs::Dynamic>{leanvec_dims}
7676
);
77-
// Intentionally using the same matrix for both elements of LeanVecMatricesType.
78-
// This may be required by downstream code expecting two matrices, even if they are
79-
// identical.
80-
return LeanVecMatricesType{matrix, matrix};
77+
// Create a copy of the matrix for the query matrix to avoid double free.
78+
// LeanVecMatrices expects two separate matrix objects.
79+
auto matrix_copy = matrix;
80+
return LeanVecMatricesType{std::move(matrix), std::move(matrix_copy)};
8181
}
8282
};
8383

0 commit comments

Comments
 (0)