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;
}
基于此,您认为是否存在内存泄漏或此错误。
解决方案
推荐阅读
- java - 图片未从 Firebase 存储加载
- events - 是否应该保持此流程管理器状态?
- data-visualization - [0] 在数据可视化语法中的用途
- java - 如何在不使用环境类的情况下在内部存储中创建目录?
- nunjucks - 110 个 nunjucks 导出模板代码的问题
- php - 如何避免for循环中的mysql查询
- apache-kafka - Kafka - 消息排序保证
- python - 如何使用 python 更改我的不和谐机器人的音量?
- python - 在 Flask App 而不是在烧瓶外壳中运行时出现 NameError
- apache-spark - 如何将数据从 PySpark 持久化到 Hive - 避免重复