!7532 fix concat memory leak
Merge pull request !7532 from zhaodezan/master
This commit is contained in:
commit
98f3fe665c
|
@ -26,8 +26,8 @@ typedef struct ConcatParameter {
|
|||
int axis_;
|
||||
int thread_count_;
|
||||
int input_num_;
|
||||
const int **input_shapes_;
|
||||
const int *output_shapes_;
|
||||
int **input_shapes_;
|
||||
int *output_shapes_;
|
||||
int64_t after_axis_size;
|
||||
int64_t count_unit_;
|
||||
} ConcatParameter;
|
||||
|
|
|
@ -35,7 +35,7 @@ int DoQuantizeToInt8FromFp32(float *real_values, int8_t *quant_values, float sca
|
|||
}
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
float temp = round(real_values[i] / scale + zp);
|
||||
float temp = round(real_values[i] * 1.0 / scale + zp);
|
||||
if (temp > 127) {
|
||||
quant_values[i] = 127;
|
||||
} else if (temp < -128) {
|
||||
|
|
|
@ -67,7 +67,7 @@ int ConcatInt8CPUKernel::ReSize() {
|
|||
}
|
||||
auto input_num = in_tensors_.size();
|
||||
concat_param_->input_num_ = input_num;
|
||||
concat_param_->input_shapes_ = reinterpret_cast<const int **>(malloc(sizeof(int *) * input_num));
|
||||
concat_param_->input_shapes_ = reinterpret_cast<int **>(malloc(sizeof(int *) * input_num));
|
||||
if (concat_param_->input_shapes_ == nullptr) {
|
||||
MS_LOG(ERROR) << "malloc concat_param_->input_shapes_ failed.";
|
||||
return RET_ERROR;
|
||||
|
@ -80,8 +80,7 @@ int ConcatInt8CPUKernel::ReSize() {
|
|||
<< " failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
memcpy(reinterpret_cast<void *>(const_cast<int *>(concat_param_->input_shapes_[i])), in_shape.data(),
|
||||
sizeof(int) * in_shape.size());
|
||||
memcpy(reinterpret_cast<void *>(concat_param_->input_shapes_[i]), in_shape.data(), sizeof(int) * in_shape.size());
|
||||
}
|
||||
|
||||
before_axis_size = 1;
|
||||
|
@ -98,7 +97,7 @@ int ConcatInt8CPUKernel::ReSize() {
|
|||
MS_LOG(ERROR) << "malloc concat_param_->output_shapes_ failed.";
|
||||
return RET_ERROR;
|
||||
}
|
||||
memcpy(reinterpret_cast<void *>(const_cast<int *>(concat_param_->output_shapes_)), output_tensor->shape().data(),
|
||||
memcpy(reinterpret_cast<void *>(concat_param_->output_shapes_), output_tensor->shape().data(),
|
||||
sizeof(int) * output_dim);
|
||||
|
||||
for (size_t i = axis_ + 1; i < output_dim; i++) {
|
||||
|
|
|
@ -36,6 +36,16 @@ class ConcatInt8CPUKernel : public ConcatBaseCPUKernel {
|
|||
if (input_data_ != nullptr) {
|
||||
free(input_data_);
|
||||
}
|
||||
int *output_shape = concat_param_->output_shapes_;
|
||||
if (output_shape != nullptr) {
|
||||
free(output_shape);
|
||||
}
|
||||
for (std::size_t i = 0; i < in_tensors().size(); i++) {
|
||||
int *input_shape = concat_param_->input_shapes_[i];
|
||||
if (input_shape != nullptr) {
|
||||
free(input_shape);
|
||||
}
|
||||
}
|
||||
if (concat_param_->input_shapes_ != nullptr) {
|
||||
free(concat_param_->input_shapes_);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue