mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-25 19:48:11 +00:00
[OpenVINO]Fix memory leak upon exception throwing (#5954)
1. Make sure to free the output_shape vector even if Output names mismatch between OpenVINO and ONNX exception is thrown 2. Piggy back this PR to remove un-needed call to fstream close method Authored-by: modav <modav@microsoft.com>
This commit is contained in:
parent
015fbb3dbb
commit
5f5d4a10bd
1 changed files with 4 additions and 7 deletions
|
|
@ -36,7 +36,6 @@ bool IsDebugEnabled() {
|
|||
void DumpOnnxModelProto(const Provider_ModelProto& model_proto, std::string file_name) {
|
||||
std::fstream outfile(file_name, std::ios::out | std::ios::trunc | std::ios::binary);
|
||||
model_proto.SerializeToOstream(outfile);
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -187,7 +186,7 @@ GetOutputTensor(Ort::CustomOpApi& ort, OrtKernelContext* context, size_t batch_s
|
|||
graph_output_dims.insert(graph_output_dims.begin(), batch_size);
|
||||
}
|
||||
size_t num_dims = graph_output_dims.size();
|
||||
auto output_shape = new int64_t[num_dims];
|
||||
std::unique_ptr<int64_t[]> output_shape(new int64_t[num_dims]);
|
||||
for (size_t j = 0; j < num_dims; j++) {
|
||||
output_shape[j] = static_cast<int64_t>(graph_output_dims[j]);
|
||||
}
|
||||
|
|
@ -197,8 +196,7 @@ GetOutputTensor(Ort::CustomOpApi& ort, OrtKernelContext* context, size_t batch_s
|
|||
}
|
||||
int index = it->second;
|
||||
|
||||
output_tensor = ort.KernelContext_GetOutput(context, index, output_shape, num_dims);
|
||||
delete[] output_shape;
|
||||
output_tensor = ort.KernelContext_GetOutput(context, index, output_shape.get(), num_dims);
|
||||
|
||||
return output_tensor;
|
||||
}
|
||||
|
|
@ -218,12 +216,11 @@ GetOutputTensor(Ort::CustomOpApi& ort, OrtKernelContext* context,
|
|||
auto shape = node->get_shape();
|
||||
|
||||
size_t num_dims = shape.size();
|
||||
auto output_shape = new int64_t[num_dims];
|
||||
std::unique_ptr<int64_t[]> output_shape(new int64_t[num_dims]);
|
||||
for (size_t j = 0; j < num_dims; j++) {
|
||||
output_shape[j] = static_cast<int64_t>(shape[j]);
|
||||
}
|
||||
output_tensor = ort.KernelContext_GetOutput(context, index, output_shape, num_dims);
|
||||
delete[] output_shape;
|
||||
output_tensor = ort.KernelContext_GetOutput(context, index, output_shape.get(), num_dims);
|
||||
|
||||
return output_tensor;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue