在fortify Static Code Analyser中使用C++11中的std::unique_ptr
会导致内存泄漏。
void *httpServerThread(void *arg)
{
std::unique_ptr <int> i(new int(1));
return NULL;
}
同时,下面的代码显示没有内存泄漏。
void *httpServerThread(void *arg)
{
int * i = new int(1);
delete i;
return NULL;
}
由于没有std::make_unique
,因此没有new
就无法创建std::unique_ptr
。 我使用的是Fortify->的19.2.0版本; FORTIFY_SCA_AND_APPS_19.2.0。 欢迎提出任何建议。
显示的函数中没有内存泄漏。 该消息为误报。
由于没有std::make_unique,因此没有new就无法创建std::unique_ptr。
注意,您可以编写自己的make_unique
。 当然,该函数必须使用new
,但其他函数都不需要。