Browse Source

avoid double free for tdt channel

pull/13629/head
ms_yan 4 years ago
parent
commit
c59349e096
3 changed files with 15 additions and 5 deletions
  1. +8
    -3
      mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_handle.cc
  2. +2
    -0
      mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_handle.h
  3. +5
    -2
      mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_plugin.cc

+ 8
- 3
mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_handle.cc View File

@@ -26,14 +26,19 @@ void TdtHandle::AddHandle(acltdtChannelHandle *handle) {
} }


bool TdtHandle::DestroyHandle() { bool TdtHandle::DestroyHandle() {
for (auto handle : acl_handle) {
bool destroy_all = true;
for (auto &handle : acl_handle) {
if (handle != nullptr) { if (handle != nullptr) {
if (acltdtDestroyChannel(handle) != ACL_SUCCESS) { if (acltdtDestroyChannel(handle) != ACL_SUCCESS) {
return false;
destroy_all = false;
} else {
handle = nullptr;
} }
} }
} }
return true;
return destroy_all;
} }

std::vector<acltdtChannelHandle *> TdtHandle::GetHandle() { return acl_handle; }
} // namespace dataset } // namespace dataset
} // namespace mindspore } // namespace mindspore

+ 2
- 0
mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_handle.h View File

@@ -28,6 +28,8 @@ class TdtHandle {


static bool DestroyHandle(); static bool DestroyHandle();


static std::vector<acltdtChannelHandle *> GetHandle();

private: private:
TdtHandle() {} TdtHandle() {}




+ 5
- 2
mindspore/ccsrc/minddata/dataset/engine/tdt/tdt_plugin.cc View File

@@ -33,8 +33,11 @@ TdtPlugin::TdtPlugin(const std::string &channel_name, int32_t device_id) {
} }


TdtPlugin::~TdtPlugin() { TdtPlugin::~TdtPlugin() {
if (acl_handle_ != nullptr && acltdtDestroyChannel(acl_handle_) != ACL_SUCCESS) {
MS_LOG(ERROR) << "Failed to destroy channel for tdt queue.";
std::vector<acltdtChannelHandle *> total_handle = TdtHandle::GetHandle();
if (std::find(total_handle.begin(), total_handle.end(), acl_handle_) != total_handle.end()) {
if (acl_handle_ != nullptr && acltdtDestroyChannel(acl_handle_) != ACL_SUCCESS) {
MS_LOG(ERROR) << "Failed to destroy channel for tdt queue.";
}
} }
} }




Loading…
Cancel
Save