Skip to content

Commit

Permalink
Fix malloc/delete[] mismatch
Browse files Browse the repository at this point in the history
It's not correct to use delete[] to free a malloc allocation.
This commit changes those allocations to use std::make_unique<int[]>,
so we no longer need manual deallocation.

Fixes #807.
  • Loading branch information
mhoemmen committed Sep 7, 2022
1 parent 8c639d9 commit fb4572c
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions cpp/test/sparse/sort.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <raft/sparse/op/sort.cuh>

#include <iostream>
#include <memory>

namespace raft {
namespace sparse {
Expand Down Expand Up @@ -60,30 +61,26 @@ 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<int[]>(params.nnz);
auto in_cols_h = std::make_unique<int[]>(params.nnz);
auto verify_h = std::make_unique<int[]>(params.nnz);

for (int i = 0; i < params.nnz; i++) {
in_rows_h[i] = params.nnz - i - 1;
verify_h[i] = i;
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<int>(
verify.data(), in_rows.data(), params.nnz, raft::Compare<int>(), stream));

delete[] in_rows_h;
delete[] in_cols_h;
delete[] verify_h;
}

INSTANTIATE_TEST_CASE_P(SparseSortTest, COOSort, ::testing::ValuesIn(inputsf));
Expand Down

0 comments on commit fb4572c

Please sign in to comment.