OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[TF FE] Indirect leak on ONNX FE - variables_index.cpp (#36087)
Szymon Gutaj340a9aabf2fb
diff --git a/src/frontends/tensorflow/src/variables_index.cpp b/src/frontends/tensorflow/src/variables_index.cppindex f287038fb8b..604bc6f8df8 100644--- a/src/frontends/tensorflow/src/variables_index.cpp+++ b/src/frontends/tensorflow/src/variables_index.cpp@@ -372,7 +372,19 @@ void VariablesIndex::map_assignvariable(const std::shared_ptr<::tensorflow::Grapstd::map<std::string, std::string>& variables_map,HashTableKeysValuesMap& hash_table_keys_map,HashTableKeysValuesMap& hash_table_values_map) {- std::map<std::string, PtrNode::SharedPtrNode> nodes;+ using Nodes = std::map<std::string, PtrNode::SharedPtrNode>;+ Nodes nodes;++ // Removing cross-links, otherwise memory leak will be caused by lost shared pointers+ auto cross_link_deleter = [](Nodes* const nodes) {+ for (auto& node : *nodes) {+ node.second->inputs.clear();+ node.second->outputs.clear();+ }+ nodes->clear();+ };++ std::unique_ptr<Nodes, decltype(cross_link_deleter)> cross_link_guard(&nodes, cross_link_deleter);for (const auto& node : graph_def->node()) {auto shared_node = std::make_shared<PtrNode>(node);@@ -525,14 +537,6 @@ void VariablesIndex::map_assignvariable(const std::shared_ptr<::tensorflow::Graphash_table_values_map[hash_tablev2_name] = values_const;}}-- // Removing cross-links, otherwise memory leak will be caused by lost shared pointers- for (auto node : nodes) {- node.second->inputs.clear();- node.second->outputs.clear();- }-- nodes.clear();}} // namespace tensorflow