ubuntu使用valgrind检查C++的helloworld程序出错

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
liulili
帖子: 2
注册时间: 2017-11-10 11:03
系统: win10

ubuntu使用valgrind检查C++的helloworld程序出错

#1

帖子 liulili » 2017-11-10 11:20

使用valgrind检测程序,发现始终有内存泄露的问题,在网上找了很久没有找到向相关的资料,这里求助一下各位大大,先向各位说声谢谢

详细内容如下:

root@ubuntu:/home/ubuntu/temp# cat main.cpp
#include "iostream"

using namespace std;


int main()
{
cout <<"hello world" << endl;
return 0;
}
root@ubuntu:/home/ubuntu/temp# g++ -g main.cpp -o qwe
root@ubuntu:/home/ubuntu/temp# ls
main.cpp qwe
root@ubuntu:/home/ubuntu/temp# ./qwe
hello world
root@ubuntu:/home/ubuntu/temp# valgrind ./qwe
==15976== Memcheck, a memory error detector
==15976== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==15976== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==15976== Command: ./qwe
==15976==
hello world
==15976==
==15976== HEAP SUMMARY:
==15976== in use at exit: 72,704 bytes in 1 blocks
==15976== total heap usage: 2 allocs, 1 frees, 73,728 bytes allocated
==15976==
==15976== LEAK SUMMARY:
==15976== definitely lost: 0 bytes in 0 blocks
==15976== indirectly lost: 0 bytes in 0 blocks
==15976== possibly lost: 0 bytes in 0 blocks
==15976== still reachable: 72,704 bytes in 1 blocks
==15976== suppressed: 0 bytes in 0 blocks
==15976== Rerun with --leak-check=full to see details of leaked memory
==15976==
==15976== For counts of detected and suppressed errors, rerun with: -v
==15976== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
头像
astolia
论坛版主
帖子: 6436
注册时间: 2008-09-18 13:11

Re: ubuntu使用valgrind检查C++的helloworld程序出错

#2

帖子 astolia » 2017-11-11 9:56

找资料要用google,编程问题用英文
我用关键字 valgrind c++ hello world leak 去搜,第一条就是
https://stackoverflow.com/questions/358 ... ello-world
里面就回答了这个问题
liulili
帖子: 2
注册时间: 2017-11-10 11:03
系统: win10

Re: ubuntu使用valgrind检查C++的helloworld程序出错

#3

帖子 liulili » 2017-11-11 16:22

astolia 写了:找资料要用google,编程问题用英文
我用关键字 valgrind c++ hello world leak 去搜,第一条就是
<!-- m --><a class="postlink" href="https://stackoverflow.com/questions/358 ... stions/358 ... ello-world</a><!-- m -->
里面就回答了这个问题
感谢指导
回复