From d71d97687591db13f27ddcdf23a266ad7f2c4741 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gabr=C3=ADel=20Arth=C3=BAr=20P=C3=A9tursson?= Date: Sat, 3 Jun 2017 23:08:22 +0000 Subject: [PATCH] Fix memory leak in ValidateBinaryUsingContextAndValidationState --- source/validate.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/validate.cpp b/source/validate.cpp index a24c60e..03bc6d9 100644 --- a/source/validate.cpp +++ b/source/validate.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -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( + 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."; -- 2.7.4