From b5b66a365d46ee7f757980517631dfb739a490fa Mon Sep 17 00:00:00 2001 From: Mark Hoemmen Date: Wed, 7 Sep 2022 08:43:30 -0600 Subject: [PATCH] Fix malloc/delete mismatch (#808) Fix `malloc` allocations that use `delete[]` for deallocation, by using `std::make_unique` to manage memory instead. Fixes #807. Authors: - Mark Hoemmen (https://github.com/mhoemmen) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: https://github.com/rapidsai/raft/pull/808 --- cpp/test/sparse/sort.cu | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cpp/test/sparse/sort.cu b/cpp/test/sparse/sort.cu index ecea5344e7..645e01052a 100644 --- a/cpp/test/sparse/sort.cu +++ b/cpp/test/sparse/sort.cu @@ -22,6 +22,7 @@ #include #include +#include namespace raft { namespace sparse { @@ -60,9 +61,9 @@ TEST_P(COOSort, Result) uniform(h, r, in_vals.data(), params.nnz, float(-1.0), float(1.0)); - int* in_rows_h = (int*)malloc(params.nnz * sizeof(int)); - int* in_cols_h = (int*)malloc(params.nnz * sizeof(int)); - int* verify_h = (int*)malloc(params.nnz * sizeof(int)); + auto in_rows_h = std::make_unique(params.nnz); + auto in_cols_h = std::make_unique(params.nnz); + auto verify_h = std::make_unique(params.nnz); for (int i = 0; i < params.nnz; i++) { in_rows_h[i] = params.nnz - i - 1; @@ -70,20 +71,16 @@ TEST_P(COOSort, Result) in_cols_h[i] = i; } - raft::update_device(in_rows.data(), in_rows_h, params.nnz, stream); + raft::update_device(in_rows.data(), in_rows_h.get(), params.nnz, stream); - raft::update_device(in_cols.data(), in_cols_h, params.nnz, stream); - raft::update_device(verify.data(), verify_h, params.nnz, stream); + raft::update_device(in_cols.data(), in_cols_h.get(), params.nnz, stream); + raft::update_device(verify.data(), verify_h.get(), params.nnz, stream); op::coo_sort( params.m, params.n, params.nnz, in_rows.data(), in_cols.data(), in_vals.data(), stream); ASSERT_TRUE(raft::devArrMatch( verify.data(), in_rows.data(), params.nnz, raft::Compare(), stream)); - - delete[] in_rows_h; - delete[] in_cols_h; - delete[] verify_h; } INSTANTIATE_TEST_CASE_P(SparseSortTest, COOSort, ::testing::ValuesIn(inputsf));