This issue comes from a Codex global scan of deepmodeling/deepmd-kit at commit 73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.
Problem
Several TensorFlow C++ API wrappers create a tensorflow::Session with NewSession, but their destructors only delete the GraphDef.
DeepPotTF creates the session here:
|
check_status(NewSession(options, &session)); |
- Its destructor only deletes
graph_def:
|
DeepPotTF::~DeepPotTF() { delete graph_def; } |
- The raw session pointer is stored in the class:
|
tensorflow::Session* session; |
The same lifetime pattern appears in the other TensorFlow API wrappers:
DeepSpinTF creates a session at
|
check_status(NewSession(options, &session)); |
, but its destructor only deletes graph_def at
|
DeepSpinTF::~DeepSpinTF() { delete graph_def; } |
.
DeepTensorTF creates a session at
|
deepmd::check_status(NewSession(options, &session)); |
, but its destructor only deletes graph_def at
|
DeepTensorTF::~DeepTensorTF() { delete graph_def; } |
.
DipoleChargeModifierTF creates a session at
|
deepmd::check_status(NewSession(options, &session)); |
, but its destructor only deletes graph_def at
|
DipoleChargeModifierTF::~DipoleChargeModifierTF() { delete graph_def; }; |
.
The constructor catch blocks also only delete graph_def if init() throws, so failures after NewSession can leak the partially constructed session before the destructor can run.
Impact
Repeated construction/destruction of TensorFlow C++ API objects can leak TensorFlow sessions, including associated CPU/GPU resources and runtime threads. This is especially relevant for long-running host applications, plugins, or test processes that load many models.
Suggested fix
Close and delete the TensorFlow session in each destructor, and clean it up on constructor failure after NewSession succeeds. Prefer RAII ownership for both session and graph_def so partial initialization and exceptions follow the same cleanup path.
This issue comes from a Codex global scan of
deepmodeling/deepmd-kitat commit73de44b1f94471b2e3bdb6b11f57b34d7bc791bb.Problem
Several TensorFlow C++ API wrappers create a
tensorflow::SessionwithNewSession, but their destructors only delete theGraphDef.DeepPotTFcreates the session here:deepmd-kit/source/api_cc/src/DeepPotTF.cc
Line 458 in 73de44b
graph_def:deepmd-kit/source/api_cc/src/DeepPotTF.cc
Line 419 in 73de44b
deepmd-kit/source/api_cc/include/DeepPotTF.h
Line 296 in 73de44b
The same lifetime pattern appears in the other TensorFlow API wrappers:
DeepSpinTFcreates a session atdeepmd-kit/source/api_cc/src/DeepSpinTF.cc
Line 458 in 73de44b
graph_defatdeepmd-kit/source/api_cc/src/DeepSpinTF.cc
Line 419 in 73de44b
DeepTensorTFcreates a session atdeepmd-kit/source/api_cc/src/DeepTensorTF.cc
Line 57 in 73de44b
graph_defatdeepmd-kit/source/api_cc/src/DeepTensorTF.cc
Line 23 in 73de44b
DipoleChargeModifierTFcreates a session atdeepmd-kit/source/api_cc/src/DataModifierTF.cc
Line 60 in 73de44b
graph_defatdeepmd-kit/source/api_cc/src/DataModifierTF.cc
Line 26 in 73de44b
The constructor catch blocks also only delete
graph_defifinit()throws, so failures afterNewSessioncan leak the partially constructed session before the destructor can run.Impact
Repeated construction/destruction of TensorFlow C++ API objects can leak TensorFlow sessions, including associated CPU/GPU resources and runtime threads. This is especially relevant for long-running host applications, plugins, or test processes that load many models.
Suggested fix
Close and delete the TensorFlow session in each destructor, and clean it up on constructor failure after
NewSessionsucceeds. Prefer RAII ownership for bothsessionandgraph_defso partial initialization and exceptions follow the same cleanup path.