Coverity指向潜在的内存泄漏

时间:2018-11-07 12:37:31

标签: c++ coverity

在以下代码中,Coverity指出潜在的内存泄漏。

m_threads.create_thread(boost::bind(&boost::asio::io_service::run, &m_ioService));

覆盖率错误如下:

CID 223450 (#1 of 1): Resource leak (RESOURCE_LEAK)
8. leaked_storage: Ignoring storage allocated by this->m_threads.create_thread(boost::bind(&run, &this->m_ioService)) leaks it

create_thread的代码如下:

template<typename F>
thread* create_thread(F threadfunc)
{
    boost::lock_guard<shared_mutex> guard(m);
    std::auto_ptr<thread> new_thread(new thread(threadfunc));
    threads.push_back(new_thread.get());
    return new_thread.release();
}

new_thread的类型为:

std::auto_ptr<thread> new_thread(new thread(threadfunc));

线程类型为:

std::list<thread*> threads;

thread_group类的析构函数(具有create_thread和成员线程方法)将删除所有线程:

  for(std::list<thread*>::iterator it=threads.begin(),end=threads.end();
     it!=end;
     ++it)
 {
     delete *it;
 }

基于此,您认为存在内存泄漏,或者这是一个假阳性。

0 个答案:

没有答案