C ++ valgrind在Hello World中显示内存泄漏 [英] c++ valgrind shows memory leak in hello world

查看:104
本文介绍了C ++ valgrind在Hello World中显示内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序的代码是

#include <iostream>

int main(int argc, const char *argv[])
{
  std::cout << "hello world!\n";
  return 0;
}

我用标志对其进行了编译

I compiled it with flags

-Wpedantic -pedantic-errors -std=c++11 -g -Wall -Wextra

在其上运行Valgrind并看到一些奇怪的东西,这个简单的程序存在内存泄漏,valgrind --leak-check=full --show-leak-kinds=all命令的输出为

Run Valgrind on it and saw something strange, this simple program has memory leak, output of valgrind --leak-check=full --show-leak-kinds=all command is

==4492== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==4492==    at 0x4C28C20: malloc (vg_replace_malloc.c:296)
==4492==    by 0x4EBF11F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
==4492==    by 0x400E9F9: call_init.part.0 (dl-init.c:78)
==4492==    by 0x400EAE2: call_init (dl-init.c:36)
==4492==    by 0x400EAE2: _dl_init (dl-init.c:126)
==4492==    by 0x40011C9: ??? (in /lib/x86_64-linux-gnu/ld-2.19.so)

我的问题是-如何找出正在发生的事情?

my question is - how to find out what is going on?

推荐答案

这是linux系统动态库加载程序永久保留的内存.找出正在发生的事情的方法包括读取_dl_init()函数的代码,例如:

This is memory reserved forever by linux system dynamic library loader. Ways to find out what's going on include reading code for _dl_init() function, e.g.: here. Another option is to step-through your program with debugger, you'll want to break _init before run and probably also use disassemble and si, as glibc can't be built unoptimized.

此处中查看讨论(可能标记为作为dup)

See discussion here (and probably mark as dup)

这篇关于C ++ valgrind在Hello World中显示内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆