possibly lost: 2,880 bytes in 10 blocks

無名小伙 2014-03-17 02:50:58

#include <iostream>
#include <pthread.h>
#include <vector>
using namespace std;

void* thread_func(void* args)
{
return 0;
}

int main(int argc,char *argv[])
{
if(argc!=2)
{
cout<<"Run with:"<<argv[0]<<" thread_count"<<endl;
return -1;
}
unsigned int NUM_THREADS= atoi(argv[1]);
pthread_t tids[NUM_THREADS];
for(int i = 0; i < NUM_THREADS; ++i)
{
int ret = pthread_create(&tids[i], NULL, thread_func, NULL);
if (ret != 0)
{
sleep(2);
cout << "pthread_create error: error_code=" << ret << endl;
}
}
pthread_exit(NULL);
}



==12919== Memcheck, a memory error detector
==12919== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==12919== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==12919== Command: /etc/SU/leak 10
==12919== Parent PID: 20231
==12919==
==12919==
==12919== HEAP SUMMARY:
==12919== in use at exit: 2,880 bytes in 10 blocks
==12919== total heap usage: 15 allocs, 5 frees, 5,384 bytes allocated
==12919==
==12919== 2,880 bytes in 10 blocks are possibly lost in loss record 1 of 1
==12919== at 0x4C266D5: calloc (vg_replace_malloc.c:593)
==12919== by 0x4011892: _dl_allocate_tls (in /lib64/ld-2.12.so)
==12919== by 0x4E35068: pthread_create@@GLIBC_2.2.5 (in /lib64/libpthread-2.12.so)
==12919== by 0x400B62: main (in /leak)
==12919== by 0x5809CDC: __libc_start_main (in /lib64/libc-2.12.so)
==12919== by 0x400948: ??? (in /leak)
==12919== by 0x7FF000737: ???
==12919== by 0x1B: ???
==12919== by 0x1: ???
==12919== by 0x7FF0009DA: ???
==12919== by 0x7FF0009E7: ???
==12919==
==12919== LEAK SUMMARY:
==12919== definitely lost: 0 bytes in 0 blocks
==12919== indirectly lost: 0 bytes in 0 blocks
==12919== possibly lost: 2,880 bytes in 10 blocks
==12919== still reachable: 0 bytes in 0 blocks
==12919== suppressed: 0 bytes in 0 blocks
==12919==
==12919== For counts of detected and suppressed errors, rerun with: -v
==12919== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

请问红色部分,有memory leak 吗?
...全文
148 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
無名小伙 2014-03-19
  • 打赏
  • 举报
回复
楼上正解~~
叶之香 2014-03-17
  • 打赏
  • 举报
回复
pthread_create导致的内存泄露 http://www.cnblogs.com/bits/archive/2009/12/04/no_join_or_detach_memory_leak.html

64,663

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧