Klocwork 2020.1 内部版本 20.1.0.97
// Vertices of simplex
auto v = new double*[n + 1]; // this line give the error
// Average coordinates
auto v_ave = new double[n];
// Reflection coordinates
auto v_ref = new double[n];
// Expansion coordinates
auto v_exp = new double[n];
// Contraction coordinates
auto v_con = new double[n];
if (v == nullptr || v_ave == nullptr || v_ref == nullptr || v_exp == nullptr || v_con == nullptr)
{
status = false;
goto free_mem;
}
// Allocate the columns of the arrays
for (int idx = 0; idx <= n; idx++)
{
v[idx] = new double[n];
if (v[idx] == nullptr)
{
status = false;
goto free_mem;
}
}
....这就是内存空闲的方式
free_mem:
if (v != nullptr)
{
// Free memory
for (int idx = 0; idx <= n; idx++)
{
delete[] v[idx];
}
delete[] v;
}
delete[] v_ave;
delete[] v_ref;
delete[] v_con;
delete[] v_exp;
return pair<double, bool>(min, status);
我不明白这个问题,也找不到任何修复建议。