瓦尔格林德:块肯定在损失记录中丢失.在新线程中
valgrind: blocks are definitely lost in loss record... in new thread
我运行这段代码,我从Valgrind收到这条消息,我是c ++和Linux新手,但我知道我必须修复它。 请您告知出了什么问题吗?我正在使用 Ubuntu。
消息是这样的:
==29304== Thread 1:
==29304== 72 bytes in 18 blocks are definitely lost in loss record 55 of 89
==29304== at 0x402641D: operator new(unsigned int) (vg_replace_malloc.c:255)
==29304== by 0x4032BBC: GmpPipePlayer::GmpPipePlayer(IOBase*, Referee*, unsigned char, int, DataBoard const*, int, char const*, int) (unixgmppipe.cpp:126)
==29304== by 0x40329F9: GmpPipePlayer::CreateFunc(IOBase*, Referee*, unsigned char, int, DataBoard const*, void*) (unixgmppipe.cpp:55)
代码为: 向下[2],向上[2];
pipe(down);
pipe(up);
_pid = fork();
if (_pid < 0)
exit(1);
if (_pid == 0)
{
close(down[1]);
close(up[0]);
dup2(down[0], 0);
dup2(up[1], 1);
execl("/bin/sh", "sh", "-c", cmd_line, NULL);
_exit(1);
}
close(down[0]);
close(up[1]);
_down = down[1];
_up = up[0];
_reader_thd = new Thread(reader_wrapper, this); //here is the error happening.
readre_wrapper函数为:
THREAD_Return GmpPipePlayer::reader_wrapper(void *p)
{
GmpPipePlayer *t = (GmpPipePlayer *)p;
t->reader_fn();
return NULL;
}
这个新线程被调用了很多次。 在我再次调用它之前,我执行以下操作:
if (_pid > 0)
{
kill(_pid, SIGTERM);
_pid = 0;
}
if (_up)
{
close(_up);
_up = 0;
}
if (_down)
{
close(_down);
_down = 0;
}
任何想法出了什么问题?
好吧,您有一个从未与delete
匹配的new
。在代码中的某个时刻,您需要一个delete _reader_thd;
。或者根本不使用动态对象。
相关文章:
- 从不同线程使用int64的不同字节安全吗
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 在C++中使用cURL和多线程
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在cuda线程之间共享大量常量数据
- 多线程:线程或进程.h - C++
- BOOST线程:线程还是进程
- 如何在线程线程内部制作内存?
- C++ - 多线程 - 线程之间的通信
- C++多线程:线程安全的内存分配
- 如何在 Linux 上强制 g++ 在协程切换线程时更新线程指针(对于 TLS)
- 如何确定流程的"经理"和"工作线程"线程的优先级(或为其设置调度策略)?
- 一旦另一个线程完成,就会生成一个新线程
- 是boost::线程线程安全的
- c++多线程-线程安全的代码
- 依靠额外的线程-线程安全
- Linux多线程——线程不会产生任何预期的输出
- 线程-线程创建问题
- 只在前一个线程完成时创建一个新线程
- 创建新线程时在lambda内部使用unique_ptr的线程安全性