From 6f83b4149eef912a568e713fba8814f174496239 Mon Sep 17 00:00:00 2001 From: Naren Dasan Date: Wed, 24 Feb 2021 18:17:59 -0800 Subject: [PATCH] fix(//core/conversion/conversionctx): Fix memory leak in conversion context engine serialization h/t: @SakodaShintaro Signed-off-by: Naren Dasan Signed-off-by: Naren Dasan --- core/conversion/conversionctx/ConversionCtx.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/conversion/conversionctx/ConversionCtx.cpp b/core/conversion/conversionctx/ConversionCtx.cpp index 9d47026c60..04f6aafe5c 100644 --- a/core/conversion/conversionctx/ConversionCtx.cpp +++ b/core/conversion/conversionctx/ConversionCtx.cpp @@ -148,7 +148,9 @@ std::string ConversionCtx::SerializeEngine() { auto engine = builder->buildEngineWithConfig(*net, *cfg); auto serialized_engine = engine->serialize(); engine->destroy(); - return std::string((const char*)serialized_engine->data(), serialized_engine->size()); + auto engine_str = std::string((const char*)serialized_engine->data(), serialized_engine->size()); + serialized_engine->destroy(); + return engine_str; } bool ConversionCtx::CheckLayerAddition(const torch::jit::Node* n) {