Skip to content
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

crypto: reduce memory usage of SignFinal #23427

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,7 @@ void Sign::SignFinal(const FunctionCallbackInfo<Value>& args) {
return sign->CheckThrow(std::get<Error>(ret));

MallocedBuffer<unsigned char> sig =
std::get<MallocedBuffer<unsigned char>>(std::move(ret));
std::move(std::get<MallocedBuffer<unsigned char>>(ret));

Local<Object> rc =
Buffer::New(env, reinterpret_cast<char*>(sig.release()), sig.size)
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ struct MallocedBuffer {

inline bool is_empty() const { return data == nullptr; }

MallocedBuffer() : data(nullptr) {}
MallocedBuffer() : data(nullptr), size(0) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I had a patch floating around I wanted to submit with this.

explicit MallocedBuffer(size_t size) : data(Malloc<T>(size)), size(size) {}
MallocedBuffer(T* data, size_t size) : data(data), size(size) {}
MallocedBuffer(MallocedBuffer&& other) : data(other.data), size(other.size) {
Expand Down