[Bug c++/25849] New: 8 byte memory leak using cerr with libpthread linked in

2006-01-18 Thread loizeaux1 at hotmail dot com
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 

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::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)
  BlocksBytes
  Leaked   18
  Potentially Leaked   00
  In-Use   00
  -
 Total Allocated   18



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



[Bug libstdc++/25849] 8 byte memory leak using cerr with libpthread linked in

2006-01-19 Thread loizeaux1 at hotmail dot com


--- 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 
#include 

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 ([EMAIL PROTECTED])
(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 (0XB000)
==22877== Reading syms from /lib/ld-2.3.4.so (0xB100)
==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: