Fix memory leak in ValidateBinaryUsingContextAndValidationState

This commit is contained in:
Gabríel Arthúr Pétursson 2017-06-03 23:08:22 +00:00
parent 66fc10564c
commit d71d976875

View File

@ -20,6 +20,7 @@
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
@ -236,18 +237,19 @@ spv_result_t spvValidate(const spv_const_context context,
spv_result_t ValidateBinaryUsingContextAndValidationState(
const spv_context_t& context, const uint32_t* words, const size_t num_words,
spv_diagnostic* pDiagnostic, ValidationState_t* vstate) {
spv_const_binary binary = new spv_const_binary_t{words, num_words};
auto binary = std::unique_ptr<spv_const_binary_t>(
new spv_const_binary_t{words, num_words});
spv_endianness_t endian;
spv_position_t position = {};
if (spvBinaryEndianness(binary, &endian)) {
if (spvBinaryEndianness(binary.get(), &endian)) {
return libspirv::DiagnosticStream(position, context.consumer,
SPV_ERROR_INVALID_BINARY)
<< "Invalid SPIR-V magic number.";
}
spv_header_t header;
if (spvBinaryHeaderGet(binary, endian, &header)) {
if (spvBinaryHeaderGet(binary.get(), endian, &header)) {
return libspirv::DiagnosticStream(position, context.consumer,
SPV_ERROR_INVALID_BINARY)
<< "Invalid SPIR-V header.";