Skip to content

Latest commit

 

History

History
168 lines (95 loc) · 23.7 KB

CppMemcheckExample1.md

File metadata and controls

168 lines (95 loc) · 23.7 KB

 

 

 

 

 

 

STLQt CreatorLubuntu

 

memcheck example 1: Hello World is a memcheck example shows how to check a Hello world program for, among others, memory leaks.

 

 

valgrind can be used from command line:

 


valgrind --leak-check=full -v --show-reachable=yes --log-file=my_log_filename.txt ./my_executable_filename

 

 

 

 

 

valgrind_memcheck.txt

 

I got the following output:

 


==13471== Memcheck, a memory error detector ==13471== Copyright 2002-2010, and GNU GPL'd, by Julian Seward et al. ==13471== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==13471== Command: ../CppMemcheckExample1-build-desktop/./CppMemcheckExample1 ==13471== Parent PID: 13470 ==13471== --13471-- --13471-- Valgrind options: --13471--    --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp --13471--    --leak-check=full --13471--    -v --13471--    --show-reachable=yes --13471--    --log-file=valgrind_memcheck.txt --13471-- Contents of /proc/version: --13471--   Linux version 2.6.38-8-generic-pae (buildd@vernadsky) (gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu3) ) #42-Ubuntu SMP Mon Apr 11 05:17:09 UTC 2011 --13471-- Arch and hwcaps: X86, x86-sse1-sse2 --13471-- Page sizes: currently 4096, max supported 4096 --13471-- Valgrind library directory: /usr/lib/valgrind --13471-- Reading syms from /lib/i386-linux-gnu/ld-2.13.so (0x4000000) --13471--   Considering /lib/i386-linux-gnu/ld-2.13.so .. --13471--   .. CRC mismatch (computed 2a2c2799 wanted 1e351f1f) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/ld-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /home/richel/Projects/Website/CppMemcheckExample1-build-desktop/CppMemcheckExample1 (0x8048000) --13471-- Reading syms from /usr/lib/valgrind/memcheck-x86-linux (0x38000000) --13471--    object doesn't have a dynamic symbol table --13471-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp --13471-- Reading suppressions file: /usr/lib/valgrind/default.supp --13471-- REDIR: 0x4016a80 (index) redirected to 0x3803f82b (vgPlain_x86_linux_REDIR_FOR_index) --13471-- Reading syms from /usr/lib/valgrind/vgpreload_core-x86-linux.so (0x4020000) --13471-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so (0x4023000) ==13471== WARNING: new redirection conflicts with existing -- ignoring it --13471--     new: 0x04016a80 (index               ) R-> 0x04026c78 index --13471-- REDIR: 0x4016c20 (strlen) redirected to 0x4027048 (strlen) --13471-- Reading syms from /usr/lib/libQtCore.so.4.7.2 (0x4043000) --13471--   Considering /usr/lib/libQtCore.so.4.7.2 .. --13471--   .. CRC mismatch (computed 0c8a8d9d wanted ce78deb8) --13471--   Considering /usr/lib/debug/usr/lib/libQtCore.so.4.7.2 .. --13471--   .. CRC is valid --13471-- Reading syms from /lib/i386-linux-gnu/libpthread-2.13.so (0x42d6000) --13471--   Considering /lib/i386-linux-gnu/libpthread-2.13.so .. --13471--   .. CRC mismatch (computed 87269ed5 wanted 7df95f2f) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/libpthread-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /usr/lib/i386-linux-gnu/libstdc++.so.6.0.14 (0x42ef000) --13471--    object doesn't have a symbol table --13471-- Reading syms from /lib/i386-linux-gnu/libm-2.13.so (0x43da000) --13471--   Considering /lib/i386-linux-gnu/libm-2.13.so .. --13471--   .. CRC mismatch (computed e686ed93 wanted a0f1e52c) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/libm-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /lib/i386-linux-gnu/libgcc_s.so.1 (0x4400000) --13471--   Considering /lib/i386-linux-gnu/libgcc_s.so.1 .. --13471--   .. CRC mismatch (computed 3fa6d24f wanted 8b2bf89f) --13471--    object doesn't have a symbol table --13471-- Reading syms from /lib/i386-linux-gnu/libc-2.13.so (0x441c000) --13471--   Considering /lib/i386-linux-gnu/libc-2.13.so .. --13471--   .. CRC mismatch (computed 97e88cd2 wanted 4635a554) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/libc-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /lib/i386-linux-gnu/libz.so.1.2.3.4 (0x457e000) --13471--   Considering /lib/i386-linux-gnu/libz.so.1.2.3.4 .. --13471--   .. CRC mismatch (computed 995eb12f wanted 33a06a21) --13471--    object doesn't have a symbol table --13471-- Reading syms from /lib/i386-linux-gnu/libdl-2.13.so (0x4593000) --13471--   Considering /lib/i386-linux-gnu/libdl-2.13.so .. --13471--   .. CRC mismatch (computed 608d0daf wanted 983d6578) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/libdl-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /usr/lib/i386-linux-gnu/libgthread-2.0.so.0.2800.6 (0x4597000) --13471--   Considering /usr/lib/i386-linux-gnu/libgthread-2.0.so.0.2800.6 .. --13471--   .. CRC mismatch (computed 244482a3 wanted 61a9cd3c) --13471--    object doesn't have a symbol table --13471-- Reading syms from /lib/i386-linux-gnu/librt-2.13.so (0x459c000) --13471--   Considering /lib/i386-linux-gnu/librt-2.13.so .. --13471--   .. CRC mismatch (computed 680ec6ea wanted 247d4d27) --13471--   Considering /usr/lib/debug/lib/i386-linux-gnu/librt-2.13.so .. --13471--   .. CRC is valid --13471-- Reading syms from /lib/i386-linux-gnu/libglib-2.0.so.0.2800.6 (0x45a5000) --13471--   Considering /lib/i386-linux-gnu/libglib-2.0.so.0.2800.6 .. --13471--   .. CRC mismatch (computed 2312631e wanted e21a44de) --13471--    object doesn't have a symbol table --13471-- Reading syms from /lib/i386-linux-gnu/libpcre.so.3.12.1 (0x467d000) --13471--   Considering /lib/i386-linux-gnu/libpcre.so.3.12.1 .. --13471--   .. CRC mismatch (computed 9e5ab3c1 wanted 29aaf7e3) --13471--    object doesn't have a symbol table --13471-- REDIR: 0x448ffb0 (strncmp) redirected to 0x4020479 (_vgnU_ifunc_wrapper) --13471-- REDIR: 0x4497140 (strstr) redirected to 0x4020479 (_vgnU_ifunc_wrapper) --13471-- REDIR: 0x4496db0 (__GI_strstr) redirected to 0x4028ef1 (strstr) --13471-- REDIR: 0x44900b0 (rindex) redirected to 0x4026acc (rindex) --13471-- REDIR: 0x439b650 (operator new(unsigned int)) redirected to 0x4026398 (operator new(unsigned int)) --13471-- REDIR: 0x448bef0 (malloc) redirected to 0x40267df (malloc) --13471-- REDIR: 0x448fd80 (__GI_strlen) redirected to 0x402702d (__GI_strlen) --13471-- REDIR: 0x448f740 (strcmp) redirected to 0x4020479 (_vgnU_ifunc_wrapper) --13471-- REDIR: 0x4538cb0 (__strcmp_ssse3) redirected to 0x40279d0 (strcmp) --13471-- REDIR: 0x43994b0 (operator delete(void*)) redirected to 0x4025882 (operator delete(void*)) --13471-- REDIR: 0x448c3b0 (free) redirected to 0x4025b6b (free) ==13471== ==13471== HEAP SUMMARY: ==13471==     in use at exit: 0 bytes in 0 blocks ==13471==   total heap usage: 8 allocs, 8 frees, 336 bytes allocated ==13471== ==13471== All heap blocks were freed -- no leaks are possible ==13471== ==13471== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 6) --13471-- --13471-- used_suppression:     33 U1004-ARM-_dl_relocate_object ==13471== ==13471== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 6)

 

Zero errors, excellent!

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

  • STL STL: GNU ISO C++ Library, version 4.9.2

 

 

 

 

 

Qt project file: ./CppMemcheckExample1/CppMemcheckExample1.pro

 


include(../../ConsoleApplication.pri) #Or use the code below # QT += core # QT += gui # greaterThan(QT_MAJOR_VERSION, 4): QT += widgets # CONFIG   += console # CONFIG   -= app_bundle # TEMPLATE = app # CONFIG(release, debug|release) { #   DEFINES += NDEBUG NTRACE_BILDERBIKKEL # } # QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ # unix { #   QMAKE_CXXFLAGS += -Werror # } SOURCES += main.cpp

 

 

 

 

 

./CppMemcheckExample1/main.cpp

 


#include <iostream> int main() {   std::cout << "Hello world\n"; }

 

 

 

 

 

./CppMemcheckExample1/valgrind_memcheck.sh

 


#!/bin/sh valgrind --leak-check=full -v --show-reachable=yes --log-file=valgrind_memcheck.txt ../CppValgrindExample1-build-desktop/./CppValgrindExample1