modulewrapper: manage buffer with |unique_ptr|. This doesn't actually matter, but ASan otherwise complains about the memory leak on process exit. Change-Id: Ic7cf591b7687f10c3a5bc304e1321f4deecdcb10 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/38804 Reviewed-by: David Benjamin <davidben@google.com> Commit-Queue: Adam Langley <agl@google.com>
diff --git a/util/fipstools/acvp/modulewrapper/modulewrapper.cc b/util/fipstools/acvp/modulewrapper/modulewrapper.cc index 109e3b0..d6a9b0a 100644 --- a/util/fipstools/acvp/modulewrapper/modulewrapper.cc +++ b/util/fipstools/acvp/modulewrapper/modulewrapper.cc
@@ -595,7 +595,7 @@ int main() { uint32_t nums[1 + kMaxArgs]; - uint8_t *buf = nullptr; + std::unique_ptr<uint8_t[]> buf; size_t buf_len = 0; Span<const uint8_t> args[kMaxArgs]; @@ -641,19 +641,15 @@ } if (need > buf_len) { - free(buf); size_t alloced = need + (need >> 1); if (alloced < need) { abort(); } - buf = reinterpret_cast<uint8_t *>(malloc(alloced)); - if (buf == nullptr) { - abort(); - } + buf.reset(new uint8_t[alloced]); buf_len = alloced; } - if (!ReadAll(STDIN_FILENO, buf, need)) { + if (!ReadAll(STDIN_FILENO, buf.get(), need)) { return 1; }