This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/13541] New: valgrind reports leak with string


valgrind reports a memory leak when I use string! 
I don't know if its true but it doesn't hurt to check it out. 
 
Linux rolomobile 2.6.0-gentoo #11 Sat Dec 27 19:49:44 AST 2003 i686 Mobile 
Intel(R) Celeron(R) CPU 1.70GHz GenuineIntel GNU/Linux 
 
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/specs 
Configured with: /var/tmp/portage/gcc-3.2.3-r3/work/gcc-3.2.3/configure 
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.2 
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include 
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2 
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/man 
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.2/info --enable-shared 
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib 
--enable-languages=c,c++,f77,objc --enable-threads=posix --enable-long-long 
--disable-checking --enable-cstdio=stdio --enable-clocale=generic 
--enable-__cxa_atexit --enable-version-specific-runtime-libs 
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/include/g++-v3 
--with-local-prefix=/usr/local --enable-shared --enable-nls 
--without-included-gettext 
Thread model: posix 
gcc version 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3, propolice) 
 
------------------------------------------ 
//to reproduce compile something like this. 
 
#include <string> 
#include <iostream> 
 
int 
main(){ 
  std::string palabra("Hola!\n"); 
  palabra+="Hola Esto es nuevo!\n"; 
  palabra+="Hola Esto es nuevo tambien\n"; 
  return 1; 
}//main(){ 
------------------------- 
g++ -ggdb str_test.cpp -o str_test 
 
valgrind --leak-check=yes --show-reachable=yes -v ./str_test 
 
valgrind reports: 
short summary: 
==4912== malloc/free: in use at exit: 4224 bytes in 2 blocks. 
==4912== malloc/free: 3 allocs, 1 frees, 4226 bytes allocated. 
 
full output: 
==4912== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux. 
==4912== Copyright (C) 2002-2003, and GNU GPL'd, by Julian Seward. 
==4912== Using valgrind-2.0.0, a program supervision framework for x86-linux. 
==4912== Copyright (C) 2000-2003, and GNU GPL'd, by Julian Seward. 
==4912== Command line: 
==4912==    ./string 
==4912== Startup, with flags: 
==4912==    --suppressions=/usr/lib/valgrind/default.supp 
==4912==    --leak-check=yes 
==4912==    --show-reachable=yes 
==4912==    -v 
==4912== Reading syms from /home/rolo/Desktop/Programming_tests/string 
==4912== Reading syms from /usr/lib/valgrind/vgskin_memcheck.so 
==4912==    object doesn't have any debug info 
==4912== Reading syms from /usr/lib/valgrind/valgrind.so 
==4912==    object doesn't have any debug info 
==4912== Reading syms from /lib/ld-2.3.2.so 
==4912==    object doesn't have any debug info 
==4912== Reading syms from /lib/libc-2.3.2.so 
==4912==    object doesn't have any debug info 
==4912== Reading syms from /lib/libm-2.3.2.so 
==4912==    object doesn't have any debug info 
==4912== Reading syms 
from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/libstdc++.so.5.0.3 
==4912==    object doesn't have any debug info 
==4912== Reading syms 
from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/libgcc_s.so.1 
==4912== Reading suppressions file: /usr/lib/valgrind/default.supp 
==4912== Estimated CPU clock rate is 1700 MHz 
==4912== 
==4912== 
==4912== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 
==4912== malloc/free: in use at exit: 4224 bytes in 2 blocks. 
==4912== malloc/free: 3 allocs, 1 frees, 4226 bytes allocated. 
==4912== 
==4912== searching for pointers to 2 not-freed blocks. 
==4912== checked 4479240 bytes. 
==4912== 
==4912== 4224 bytes in 2 blocks are still reachable in loss record 1 of 1 
==4912==    at 0x40015B41: __builtin_new 
(in /usr/lib/valgrind/vgskin_memcheck.so) 
==4912==    by 0x40015BAC: operator new(unsigned) 
(in /usr/lib/valgrind/vgskin_memcheck.so) 
==4912==    by 0x41529A40: std::__default_alloc_template<true, 
0>::_S_chunk_alloc(unsigned, int&) 
(in /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/libstdc++.so.5.0.3) 
==4912==    by 0x4152994C: std::__default_alloc_template<true, 
0>::_S_refill(unsigned) 
(in /usr/lib/gcc-lib/i686-pc-linux-gnu/3.2.3/libstdc++.so.5.0.3) 
==4912== 
==4912== LEAK SUMMARY: 
==4912==    definitely lost: 0 bytes in 0 blocks. 
==4912==    possibly lost:   0 bytes in 0 blocks. 
==4912==    still reachable: 4224 bytes in 2 blocks. 
==4912==         suppressed: 0 bytes in 0 blocks. 
==4912== 
--4912--     TT/TC: 0 tc sectors discarded. 
--4912--            866 chainings, 0 unchainings. 
--4912-- translate: new     1707 (25393 -> 320988; ratio 126:10) 
--4912--            discard 0 (0 -> 0; ratio 0:10). 
--4912--  dispatch: 0 jumps (bb entries), of which 4729 (472900%) were 
unchained. 
--4912--            2/1721 major/minor sched events.  1711 tt_fast misses. 
--4912-- reg-alloc: 188 t-req-spill, 59949+1342 orig+spill uis, 7995 
total-reg-r. 
--4912--    sanity: 3 cheap, 1 expensive checks. 
--4912--    ccalls: 6737 C calls, 58% saves+restores avoided (23106 bytes) 
--4912--            9145 args, avg 0.87 setup instrs each (2300 bytes) 
--4912--            0% clear the stack (20211 bytes) 
--4912--            2331 retvals, 36% of reg-reg movs avoided (1642 bytes)

-- 
           Summary: valgrind reports leak with string
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rolando_isaac at direcway dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13541


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]