Skip to content

Commit

Permalink
Fix malloc/delete mismatch (#808)
Browse files Browse the repository at this point in the history
Fix `malloc` allocations that use `delete[]` for deallocation, by using `std::make_unique<int[]>` to manage memory instead.

Fixes #807.

Authors:
  - Mark Hoemmen (https://github.com/mhoemmen)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #808
  • Loading branch information
mhoemmen authored Sep 7, 2022
1 parent 8c639d9 commit b5b66a3
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 b5b66a3

Please sign in to comment.