diff --git a/mace/kernels/resize_bicubic.h b/mace/kernels/resize_bicubic.h index 7245804154910b714e37a63315a7afc4ce40bf22..f8953e89bec52d8966d6915b702324de40376776 100644 --- a/mace/kernels/resize_bicubic.h +++ b/mace/kernels/resize_bicubic.h @@ -33,25 +33,27 @@ namespace kernels { static const int64_t kTableSize = (1 << 10); -inline const float *InitCoeffsTable() { +inline const std::shared_ptr InitCoeffsTable() { // Allocate and initialize coefficients table using Bicubic // convolution algorithm. // https://en.wikipedia.org/wiki/Bicubic_interpolation - float *coeffs_tab = new float[(kTableSize + 1) * 2]; + auto coeffs_tab = std::shared_ptr(new float[(kTableSize + 1) * 2], + std::default_delete()); + float *coeffs_tab_ptr = coeffs_tab.get(); static const double A = -0.75; for (int i = 0; i <= kTableSize; ++i) { float x = i * 1.0 / kTableSize; - coeffs_tab[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1; + coeffs_tab_ptr[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1; x += 1.0; - coeffs_tab[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A; + coeffs_tab_ptr[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A; } return coeffs_tab; } inline const float *GetCoeffsTable() { // Static so that we initialize it on first use - static const float *coeffs_tab = InitCoeffsTable(); - return coeffs_tab; + static const std::shared_ptr coeffs_tab = InitCoeffsTable(); + return coeffs_tab.get(); } inline int64_t Bound(int64_t val, int64_t limit) {