forked from mindspore-Ecosystem/mindspore
!13629 dataset: avoid double free when it call destroyHandle in force exist condition
From: @ms_yan Reviewed-by: Signed-off-by:
This commit is contained in:
commit
f2d2311ee8
|
@ -26,14 +26,19 @@ void TdtHandle::AddHandle(acltdtChannelHandle *handle) {
|
|||
}
|
||||
|
||||
bool TdtHandle::DestroyHandle() {
|
||||
for (auto handle : acl_handle) {
|
||||
bool destroy_all = true;
|
||||
for (auto &handle : acl_handle) {
|
||||
if (handle != nullptr) {
|
||||
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 mindspore
|
||||
|
|
|
@ -28,6 +28,8 @@ class TdtHandle {
|
|||
|
||||
static bool DestroyHandle();
|
||||
|
||||
static std::vector<acltdtChannelHandle *> GetHandle();
|
||||
|
||||
private:
|
||||
TdtHandle() {}
|
||||
|
||||
|
|
|
@ -33,8 +33,11 @@ TdtPlugin::TdtPlugin(const std::string &channel_name, int32_t device_id) {
|
|||
}
|
||||
|
||||
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…
Reference in New Issue