public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25849]  New: 8 byte memory leak using cerr with libpthread linked in
@ 2006-01-18 21:18 loizeaux1 at hotmail dot com
  2006-01-18 21:26 ` [Bug libstdc++/25849] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: loizeaux1 at hotmail dot com @ 2006-01-18 21:18 UTC (permalink / raw)
  To: gcc-bugs

If you link in libpthread with a program that uses cerr, you leak 8 bytes of
memory (determined through Purify).  I discovered this using a RHEL 3 WS box
and also had the same occur on a RHEL 4 AS box.  This will not occur when you
use cout or clog in place of cerr, or if libpthread is not linked in.

Granted, 8 bytes is a small leak, but it still is a memory leak.


> cat test.cpp
#include <iostream>

int main( int argc, char* argv[] )
{
   std::cerr << "This is a message" << std::endl;
   return 0;
}

> which purify
/usr/local/rational/releases/PurifyPlus.2003a.06.13.FixPack.0177/i386_linux2/bin/purify

> purify --version
Version 2003a.06.13 FixPack 0177 050331 Linux (32-bit)

> which g++
/app/gnu/gcc-4.0.1/bin/g++

> g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /gnu/gcc-4.0.1-src/configure --prefix=/gnu/gcc-4.0.1
Thread model: posix
gcc version 4.0.1

> uname -a
Linux testbox 2.6.9-11.ELsmp #1 SMP Fri May 20 18:26:27 EDT 2005 i686 i686 i386
GNU/Linux

> purify g++ -o test test.cpp -lpthread
Purify 2003a.06.13 FixPack 0177 050331 Linux (32-bit) (c) Copyright IBM Corp.
1992, 2005 All rights reserved.
Instrumenting: crtbegin.o cctQmZeb.o
libgcc.a................................................................................
crtend.o Linking

> test

[from PurifyPlus window]
Purify: Searching for all memory leaks...

Memory leaked: 8 bytes (100%); potentially leaked: 0 bytes (0%)

MLK: 8 bytes leaked at 0x80b4c10
   * This memory was allocated from:
         malloc         [rtlib.o]
         __cxa_get_globals [eh_globals.cc:115]
         std::uncaught_exception( void) [eh_catch.cc:138]
         std::basic_ostream< char,std::char_traights< char>> & std::operator
<<<std::char_traits< char>>(std::basic_ostream< char,std::char_traits< char>>
&, char const *) [ostream:405]
         main           [ccz2Vq3m.o]
         __libc_start_main [libc.so.6]

Purify Heap Analysis (combining supressed and unsupressed blocks)
                          Blocks        Bytes
              Leaked           1            8
  Potentially Leaked           0            0
              In-Use           0            0
  -----------------------------------------
     Total Allocated           1            8



Along with the memory leak, Purify reported two categories of uninitialized
memory reads (UMR) that are normally suppressed.  I wouldn't usually report
these, but they seem to be related (I performed some mild editing).

UMR: Uninitialized memory read (2 times):
   * This is occurring while in thread -1224099488:
         __pthread_initialize_minimal [libpthread.so.0]
         call_initialize_minimal [libpthread.so.0]
         _init          [libpthread.so.0]
         _dl_init       []
         _dl_start_user []
   * Reading 4 bytes from 0xbfffdaac on the stack of thread -1224099488.
   * Address 0xbfffdaac is      168 bytes below frame pointer in function
__pthread_initialize_minimal.
   * Command-line: test

UMR: Uninitialized memory read (128 times):
   * This is occurring while in thread -1224099488:
         __gconv_transform_internal_ascii [libc.so.6]
         wctob          [libc.so.6]
         std::ctype< wchar_t>::_M_initialize_ctype( void)
[ctype_members.cc:246]
         std::ctype< wchar_t>::ctype( unsigned) [ctype.cc:91]
         std::locale::_Impl::_Impl( unsigned) [locale_init.cc:304]
         std::locale::_S_initialize_once( void) [locale_init.cc:143]
   * Reading 4 bytes from 0xbfffd904 on the stack of thread -1224099488.
   * Address 0xbfffd904 is       84 bytes below frame pointer in function
wctob.


-- 
           Summary: 8 byte memory leak using cerr with libpthread linked in
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: loizeaux1 at hotmail dot com


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in
  2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
@ 2006-01-18 21:26 ` pinskia at gcc dot gnu dot org
  2006-01-18 21:30 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-18 21:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-01-18 21:26 -------
Can you first read:
http://gcc.gnu.org/onlinedocs/libstdc++/debug.html#mem


-- 


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in
  2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
  2006-01-18 21:26 ` [Bug libstdc++/25849] " pinskia at gcc dot gnu dot org
@ 2006-01-18 21:30 ` pinskia at gcc dot gnu dot org
  2006-01-19 17:30 ` loizeaux1 at hotmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-18 21:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-01-18 21:30 -------
Also looking at the code:
          void* v = std::malloc(sizeof(__cxa_eh_globals));
          if (v == 0 || __gthread_setspecific(init._M_key, v) != 0)
            std::terminate();

This is a false postive as we do free it in eh_globals_dtor.


-- 


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in
  2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
  2006-01-18 21:26 ` [Bug libstdc++/25849] " pinskia at gcc dot gnu dot org
  2006-01-18 21:30 ` pinskia at gcc dot gnu dot org
@ 2006-01-19 17:30 ` loizeaux1 at hotmail dot com
  2006-01-19 17:53 ` pinskia at gcc dot gnu dot org
  2006-02-14 14:08 ` levharout at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: loizeaux1 at hotmail dot com @ 2006-01-19 17:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from loizeaux1 at hotmail dot com  2006-01-19 17:30 -------
Here's the results I got after following the directions on the website you gave
me (I realize this may be moot since you pointed out that it is a false
positive, but I'll just do this for completeness' sake):

> cat test.cpp
#include <cstdlib>
#include <iostream>

extern "C" void __libc_freeres(void);

void do_something()
{
   std::cerr << "This is a message" << std::endl;
}

int main ( int argc, char* argv[] )
{
   atexit( __libc_freeres );
   do_something();
   return 0;
}

> g++ -g -O0 -o test test.cpp -lpthread

[Author's note: The webpage you forwarded gave an example of how to use
valgrind.  You left off the --tool option, which may not have been required
with version 1.0.4, but is with 2.2.0 (I have never used valgrind before, and
so I don't know when it may have changed).  I assume you wanted me to use the
"memcheck" tool option.  You might want to have someone look at that page if
you are going to give it to newbies to reference.]

> valgrind -v --tool=memcheck --num-callers=20 --leak-check=yes --leak-resolution=high --show-reachable=yes test
==22877== Memcheck, a memory error detector for x86-linux.
==22877== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==22877== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==22877== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==22877== Valgrind library directory: /usr/lib/valgrind
==22877== Command line
==22877==    test
==22877== Startup, with flags:
==22877==    -v
==22877==    --tool=memcheck
==22877==    --num-callers=yes
==22877==    --leak-check=yes
==22877==    --leak-resolution=high
==22877==    --show-reachable=yes
==22877== Contents of /proc/version:
==22877==   Linux version 2.6.9-11.ELsmp (bhcompile@decompose.build.redhat.com)
(gcc version 3.4.3 20050227 (Red Hat 3.4.3-22)) #1 SMP Fri May 20 18:26:27 EDT
2005
==22877== Reading syms from /home/john/testcase/test (0x8048000)
==22877== Reading syms from /lib/ld-2.3.4.so (0x1B8E4000)
==22877==    object doesn't have any debug info
==22877== Reading syms from /usr/lib/valgrind/stage2 (0XB0000000)
==22877== Reading syms from /lib/ld-2.3.4.so (0xB1000000)
==22877==    object doesn't have any debug info
==22877== Reading syms from /usr/lib/valgrind/vgskin_memcheck.so (0xB7CA9000)
==22877== Reading syms from /lib/tls/libc-2.3.4.so (0xB7ED2000)
==22877==    object doesn't have any debug info
==22877== Reading syms from /lib/libdl-2.3.4.so (0xB7FFB000)
==22877==    object doesn't have any debug info
==22877== Reading suppressions file: /usr/lib/valgrind/default.supp
==22877== REDIRECT soname:libc.so.6(__GI___ernno_location) to
soname:libpthread.so.0(__errno_location)
==22877== REDIRECT soname:libc.so.6(__errno_location) to
soname:libpthread.so.0(__ernno_location)
==22877== REDIRECT soname:libc.so.6(__GI___h_errno_location) to
soname:libpthread.so.0(__h_errno_location)
==22877== REDIRECT soname:libc.so.6(__h_errno_location) to
soname:libpthread.so.0(__h_errno_location)
==22877== REDIRECT soname:libc.so.6(__GI___res_state) to
soname:libpthread.so.0(__res_state)
==22877== REDIRECT soname:libc.so.6(__res_state) to
soname:libpthread.so.0(__res_state)
==22877== REDIRECT soname:libc.so.6(stpcpy) to *vgpreload_memcheck.so*(stpcpy)
==22877== REDIRECT soname:libc.so.6(strnlen) to
*vgpreload_memcheck.so*(strnlen)
==22877== REDIRECT soname:ld-linux.so.2(stpcpy) to
*vgpreload_memcheck.so*(stpcpy)
==22877== REDIRECT soname:ld-linux.so.2(strchr) to
*vgpreload_memcheck.so*(strchr)
==22877== 
==22877== Reading sysm from /usr/lib/valgrind/vg_inject.so (0x1B8FE000)
==22877== Reading syms from /usr/lib/valgrind/vgpreload_memcheck.so
(0x1B901000)
==22877== TRANSLATE: 0x1B8F5EE0 redirected to 0x1B904100
==22877== Reading syms from /usr/lib/valgrind/libpthread.so (0x1B908000)
==22877== Reading syms from /usr/lib/libstdc++.so.6.0.3 (0x26E000)
==22877==    object doesn't have a symbol table
==22877==    object doesn't have any debug info
==22877== Reading syms from /lib/tls/libm-2.3.4.so (0xC7D000)
==22877==    object doesn't have any debug info
==22877== Reading syms from /lib/libgcc_s-3.4.3-20050228.so.1 (0x244000)
==22877==    object doesn't have a symbol table
==22877==    object doesn't have any debug info
==22877== Reading syms from /lib/tls/libc-2.3.4.so (0xB52000)
==22877==    object doesn't have any debug info
==22877== Reading syms from /lib/libdl-2.3.4.so (0xCA2000)
==22877==    object doesn't have any debug info
==22877== TRANSLATE: 0x1B8E47A0 redirected to 0x52BFF040
This is a message==22877== TRANSLATE: 0xBB5E80 redirected to 0x1B9048F8

==22877== TRANSLATE: 0xBB3DB0 redirected to 0x1B904E24
==22877== 
==22877== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 18 from 1)
--22877-- 
--22877-- supp:   18 dl_relocate_object/dl_main
==22877== malloc/free: in use at exit: 208 bytes in 2 blocks.
==22877== malloc/free: 2 allocs, 0 frees, 208 bytes allocated
==22877== 
==22877== searching for pointers to 2 not-freed blocks
==22877== checked 2579704 bytes.
==22877== 
==22877== 8 bytes in 1 block are still reachable in loss record 1 of 2
==22877==    at 0x1B904984: malloc (vg_replace_malloc.c:131)
==22877==    by 0x30D490: __cxa_get_globals (in /usr/lib/libstdc++.so.6.0.3)
==22877==    by 0x30D1FE: std::uncaught_exception() (in
/usr/lib/libstdc++.so.6.0.3)
==22877==    by 0x2E40FF: std::basic_ostream<char, std::char_traits<char> >&
std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*) (in /usr/lib/libstdc++.so.6.0.3)
==22877==    by 0x8048817: do_something() (test.cpp:8)
==22877==    by 0x8048856: main (test.cpp:14)
==22877== 
==22877== LEAK SUMMARY
==22877==    definitely lost: 0 bytes in 0 blocks.
==22877==    possibly lost:   0 bytes in 0 blocks.
==22877==    still reachable: 8 bytes in 1 blocks.
==22877==         suppressed: 200 bytes in 1 blocks.
--22877--     TT/TC: 0 tc sectors discarded.
--22877--            3092 tt_fast misses.
--22877-- translate: new     2954 (54637 -> 694058; ratio 127:10)
--22877--            discard 2 (59 -> 840; ratio 142:10).
--22877-- chainings: 1837 chainings, 3 unchainings
--22877-- dispatch:  300000 jumps (bb entries); of them 31427 (10%) unchained.
--22877--            238/3675 major/minor sched events.
--22877-- reg-alloc: 648 t-req-spill, 128140+5538 orig+spill uis,
--22877--            15946 total-reg-rank
--22877--    sanity: 126 cheap, 6 expensive checks.
--22877--    ccalls: 12540 C calls, 54% saves+restores avoided (40424 bytes)
--22877--            17039 args, avg 0.87 setup instrs each (4232 bytes)
--22877--            0% clear the stack (37509 bytes)
--22877--            4925 retvals, 32% of reg-reg movs avoided (3066 bytes)


-- 

loizeaux1 at hotmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |loizeaux1 at hotmail dot com


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in
  2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
                   ` (2 preceding siblings ...)
  2006-01-19 17:30 ` loizeaux1 at hotmail dot com
@ 2006-01-19 17:53 ` pinskia at gcc dot gnu dot org
  2006-02-14 14:08 ` levharout at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-01-19 17:53 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-01-19 17:53 -------
So this is a purify bug as valgrind says the memory is still reachable which is
correct because it is a thread specific location for the main thread.  Closing
as invalid.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in
  2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
                   ` (3 preceding siblings ...)
  2006-01-19 17:53 ` pinskia at gcc dot gnu dot org
@ 2006-02-14 14:08 ` levharout at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: levharout at gmail dot com @ 2006-02-14 14:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from levharout at gmail dot com  2006-02-14 14:08 -------
(In reply to comment #4)
> So this is a purify bug as valgrind says the memory is still reachable which is
> correct because it is a thread specific location for the main thread.  Closing
> as invalid.

Hello, I tried to link with libpthread_nonshared library, and everything seems
OK with purify (there is no MLK error).


-- 

levharout at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |levharout at gmail dot com


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-14 14:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-18 21:18 [Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in loizeaux1 at hotmail dot com
2006-01-18 21:26 ` [Bug libstdc++/25849] " pinskia at gcc dot gnu dot org
2006-01-18 21:30 ` pinskia at gcc dot gnu dot org
2006-01-19 17:30 ` loizeaux1 at hotmail dot com
2006-01-19 17:53 ` pinskia at gcc dot gnu dot org
2006-02-14 14:08 ` levharout at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).