-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REVIEW] Fix malloc/delete[] mismatch #808
[REVIEW] Fix malloc/delete[] mismatch #808
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a style updated is needed, but this LGTM pending CO.
Thanks for fixing this Mark!
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could just use a std::vector here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjnolet A good point, though I would prefer not to change the test's existing behavior by zero-initializing all the elements of the arrays. (That would also hinder a sanitizer's ability to track use of uninitialized values.) It's up to you, though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I prefer the use of vectors over smart pointers for the host arrays, especially as we are just performing a loop over the array to directly populate it in the next step.
It's not a huge deal in this test, though, as it's pretty trivial.
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 rapidsai#807.
86354f9
to
fb4572c
Compare
Thanks @cjnolet ! I just reformatted the modified file. Your formatting script is fantastic, btw! It told me exactly what version of clang-format to use. Different clang-format versions change the formatting a lot, so it's really helpful that the script reports the required version. |
@gpucibot merge |
Fix
malloc
allocations that usedelete[]
for deallocation, by usingstd::make_unique<int[]>
to manage memory instead.Fixes #807.