Memory Leak in mkl_graph_util.h
@p3achyjr we have taken up this issue and are currently investigating it. @p3achyjr . I have a fix that is in line with what you mentioned. Since the variable is static, it has a life span till the program exists. So it should not cause a memory leak. The fix is being reviewed internally. Will create a PR with master branch soon.  Sounds good! Functionally I don't think this would cause unbounded memory growth but I thought I'd report just for sanity :) Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60506">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/60506">No</a>

<details><summary>Click to expand!</summary> 
 
 ### Issue Type

Bug

### Have you reproduced the bug with TF nightly?

No

### Source

source

### Tensorflow Version

2.11

### Custom Code

Yes

### OS Platform and Distribution

Debian GNU/Linux 10

### Mobile device

_No response_

### Python version

3.9

### Bazel version

6.1.1

### GCC/Compiler version

clang 12.0.1

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current Behaviour?

In [mkl_graph_util.h](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/graph/mkl_graph_util.h#L199C53-L200), we create a thread_local hash set using `new`. But it doesn't look like we ever free this memory. AddressSanitizer reports a memory leak when running a program that uses this code. Maybe we can change this to `std::unique_ptr`?

### Standalone code to reproduce the issue

```shell
// compiling with ASAN should leak.

#include "tensorflow/core/public/session.h"

using namespace ::tensorflow;

int main(int argc, char** argv) {
  GraphDef gdef;
  Scope scope;
  auto op = ops::Add(scope, ops::Const(1), ops::Const(2));
  scope.ToGraphDef(&gdef);
  std::unique_ptr<Session> session = NewSession(SessionOptions());

  std::vector<Tensor> outputs;
  session->Run({}, {}, {}, &outputs);
  return 0;
}
```


### Relevant log output

```shell
Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x14ffadad in malloc (/home/axlui/.cache/bazel/_bazel_axlui/f4685961e4a033eb3c5c8f3ed28f41d5/execroot/__main__/bazel-out/k8-opt/bin/cc/main_asan+0x14ffadad)
    #1 0x7f23a56450b4 in operator new(unsigned long) (/lib/x86_64-linux-gnu/libstdc++.so.6+0xa60b4)
    #2 0x2a67d4c6 in tensorflow::mkl_op_registry::IsMklOp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, tensorflow::DataType) /proc/self/cwd/external/org_tensorflow/tensorflow/core/graph/mkl_graph_util.h:268:10
    #3 0x2a691503 in tensorflow::MklLayoutRewritePass::CheckForNodeRewrite(tensorflow::Node const*) const /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/mkl_layout_pass.cc:3832:8
    #4 0x2a694b15 in tensorflow::MklLayoutRewritePass::RunPass(std::unique_ptr<tensorflow::Graph, std::default_delete<tensorflow::Graph> >*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/mkl_layout_pass.cc:4147:15
    #5 0x2a695b79 in tensorflow::MklLayoutRewritePass::Run(tensorflow::GraphOptimizationPassOptions const&)::$_15::operator()(std::unique_ptr<tensorflow::Graph, std::default_delete<tensorflow::Graph> >*) const /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/mkl_layout_pass.cc:4205:5
    #6 0x2a6958f2 in tensorflow::MklLayoutRewritePass::Run(tensorflow::GraphOptimizationPassOptions const&) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/mkl_layout_pass.cc:4218:7
    #7 0x2a77721a in tensorflow::OptimizationPassRegistry::RunGrouping(tensorflow::OptimizationPassRegistry::Grouping, tensorflow::GraphOptimizationPassOptions const&) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/optimization_registry.cc:73:26
    #8 0x289796a8 in tensorflow::DirectSession::CreateGraphs(tensorflow::BuildGraphOptions const&, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::unique_ptr<tensorflow::Graph, std::default_delete<tensorflow::Graph> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::unique_ptr<tensorflow::Graph, std::default_delete<tensorflow::Graph> > > > >*, std::unique_ptr<tensorflow::FunctionLibraryDefinition, std::default_delete<tensorflow::FunctionLibraryDefinition> >*, tensorflow::DirectSession::RunStateArgs*, absl::InlinedVector<tensorflow::DataType, 4ul, std::allocator<tensorflow::DataType> >*, absl::InlinedVector<tensorflow::DataType, 4ul, std::allocator<tensorflow::DataType> >*, long*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:1729:3
    #9 0x28976dfc in tensorflow::DirectSession::CreateExecutors(tensorflow::CallableOptions const&, std::unique_ptr<tensorflow::DirectSession::ExecutorsAndKeys, std::default_delete<tensorflow::DirectSession::ExecutorsAndKeys> >*, std::unique_ptr<tensorflow::DirectSession::FunctionInfo, std::default_delete<tensorflow::DirectSession::FunctionInfo> >*, tensorflow::DirectSession::RunStateArgs*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:1331:3
    #10 0x289722e2 in tensorflow::DirectSession::GetOrCreateExecutors(absl::Span<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const>, absl::Span<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const>, absl::Span<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const>, tensorflow::DirectSession::ExecutorsAndKeys**, tensorflow::DirectSession::RunStateArgs*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:1573:3
    #11 0x2897014e in tensorflow::DirectSession::Run(tensorflow::RunOptions const&, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor> > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >*, tensorflow::RunMetadata*, tsl::thread::ThreadPoolOptions const&) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:873:3
    #12 0x2896fbd3 in tensorflow::DirectSession::Run(tensorflow::RunOptions const&, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor> > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >*, tensorflow::RunMetadata*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:842:10
    #13 0x2896c1eb in tensorflow::DirectSession::Run(std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, tensorflow::Tensor> > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<tensorflow::Tensor, std::allocator<tensorflow::Tensor> >*) /proc/self/cwd/external/org_tensorflow/tensorflow/core/common_runtime/direct_session.cc:472:10
    #14 0x1504aef5 in nn::NNInterface::Infer() /proc/self/cwd/cc/nn/nn_interface.cc:279:3
    #15 0x15049658 in nn::NNInterface::InferLoop() /proc/self/cwd/cc/nn/nn_interface.cc:267:5
    #16 0x1505f32b in void std::__invoke_impl<void, void (nn::NNInterface::*)(), nn::NNInterface*>(std::__invoke_memfun_deref, void (nn::NNInterface::*&&)(), nn::NNInterface*&&) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:73:14
    #17 0x1505f264 in std::__invoke_result<void (nn::NNInterface::*)(), nn::NNInterface*>::type std::__invoke<void (nn::NNInterface::*)(), nn::NNInterface*>(void (nn::NNInterface::*&&)(), nn::NNInterface*&&) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:95:14
    #18 0x1505f234 in void std::thread::_Invoker<std::tuple<void (nn::NNInterface::*)(), nn::NNInterface*> >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:264:13
    #19 0x1505f1f8 in std::thread::_Invoker<std::tuple<void (nn::NNInterface::*)(), nn::NNInterface*> >::operator()() /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:271:11
    #20 0x1505f09c in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (nn::NNInterface::*)(), nn::NNInterface*> > >::_M_run() /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/thread:215:13
    #21 0x7f23a566decf  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xceecf)
```
</details>