|
From: Attila <sa...@fr...> - 2003-10-22 15:33:23
|
Hello,
I got warning to the simple code below (exc.cpp) if I link
the pthread library like
gcc exc.cpp -lpthread -lstdc++
(-D_REENTRANT omitted for simplicity). No problem if I don't
link pthread like
gcc exc.cpp -lstdc++
I guess the libraries are linked dinamically because the
executable is only 37K.
#include <iostream>
class Exception
{
public:
int _type;
Exception(int i) : _type(i) {}
};
int main()
{
try {
throw new Exception(5);
} catch(Exception* e) {
std::cout << "gotcha! " << e->_type << std::endl;
delete(e);
}
return 0;
}
The warning message follows:
==12826== Memcheck, a.k.a. Valgrind, a memory error detector
for x86-linux.
==12826== Copyright (C) 2002-2003, and GNU GPL'd, by Julian
Seward.
==12826== Using valgrind-20031012, a program supervision
framework for x86-linux.
==12826== Copyright (C) 2000-2003, and GNU GPL'd, by Julian
Seward.
==12826== Command line:
==12826== ./a.out
==12826== Startup, with flags:
==12826== --suppressions=/usr/local/lib/valgrind/default.supp
==12826== --leak-check=yes
==12826== --num-callers=9
==12826== --show-reachable=yes
==12826== --avoid-strlen-errors=yes
==12826== -v
==12826== Reading syms from /home/avangel/test/exc/a.out
==12826== Reading syms from /lib/ld-2.3.2.so
==12826== object doesn't have any debug info
==12826== Reading syms from
/usr/local/lib/valgrind/vgskin_memcheck.so
==12826== Reading syms from /usr/local/lib/valgrind/valgrind.so
==12826== Reading syms from
/usr/local/lib/valgrind/libpthread.so
==12826== Reading syms from /usr/lib/libstdc++.so.5.0.3
==12826== object doesn't have a symbol table
==12826== object doesn't have any debug info
==12826== Reading syms from /lib/i686/libc-2.3.2.so
==12826== object doesn't have any debug info
==12826== Reading syms from /lib/i686/libm-2.3.2.so
==12826== object doesn't have any debug info
==12826== Reading syms from /lib/libgcc_s-3.2.2-20030225.so.1
==12826== object doesn't have a symbol table
==12826== object doesn't have any debug info
==12826== Reading suppressions file:
/usr/local/lib/valgrind/default.supp
==12826== Estimated CPU clock rate is 930 MHz
==12826== REPLACING libc(__GI___errno_location) with
libpthread(__errno_location)
==12826== REPLACING libc(__GI___h_errno_location) with
libpthread(__h_errno_location)
==12826== REPLACING libc(__GI___res_state) with
libpthread(__res_state)
==12826==
==12826== TRANSLATE: 0x40326CB0 redirected to 0x40227DC8
gotcha! 5
==12826== TRANSLATE: 0x40402D80 redirected to 0x40227EAC
==12826==
==12826== ERROR SUMMARY: 0 errors from 0 contexts
(suppressed: 0 from 0)
==12826== malloc/free: in use at exit: 208 bytes in 2 blocks.
==12826== malloc/free: 4 allocs, 2 frees, 296 bytes allocated.
==12826==
==12826== searching for pointers to 2 not-freed blocks.
==12826== checked 4634284 bytes.
==12826==
==12826== 8 bytes in 1 blocks are still reachable in loss
record 1 of 2
==12826== at 0x4002965E: malloc (vg_replace_malloc.c:153)
==12826== by 0x402E9086: __cxa_get_globals (in
/usr/lib/libstdc++.so.5.0.3)
==12826== by 0x402E9CFD: __cxa_throw (in
/usr/lib/libstdc++.so.5.0.3)
==12826== by 0x80490D8: main (in
/home/avangel/test/exc/a.out)
==12826== by 0x40326A06: __libc_start_main (in
/lib/i686/libc-2.3.2.so)
==12826== by 0x8048F9C: ??? (start.S:81)
==12826==
==12826== LEAK SUMMARY:
==12826== definitely lost: 0 bytes in 0 blocks.
==12826== possibly lost: 0 bytes in 0 blocks.
==12826== still reachable: 8 bytes in 1 blocks.
==12826== suppressed: 200 bytes in 1 blocks.
==12826==
--12826-- TT/TC: 0 tc sectors discarded.
--12826-- 1380 chainings, 0 unchainings.
--12826-- translate: new 2681 (41872 -> 540299; ratio
129:10)
--12826-- discard 0 (0 -> 0; ratio 0:10).
--12826-- dispatch: 0 jumps (bb entries), of which 7792
(779200%) were unchained.
--12826-- 2/3043 major/minor sched events. 2701
tt_fast misses.
--12826-- reg-alloc: 382 t-req-spill, 101433+2445 orig+spill
uis, 13051 total-reg-r.
--12826-- sanity: 3 cheap, 1 expensive checks.
--12826-- ccalls: 11222 C calls, 55% saves+restores
avoided (36958 bytes)
--12826-- 15152 args, avg 0.87 setup instrs each
(3696 bytes)
--12826-- 0% clear the stack (33666 bytes)
--12826-- 3880 retvals, 35% of reg-reg movs
avoided (2680 bytes)
system configuration:
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
glibc 2.3.2
Redhat 8
Thanks in advance,
Attila
|
|
From: Jeremy F. <je...@go...> - 2003-10-22 16:30:40
|
On Wed, 2003-10-22 at 08:21, Attila wrote: > The warning message follows: > ==12826== 8 bytes in 1 blocks are still reachable in loss > record 1 of 2 > ==12826== at 0x4002965E: malloc (vg_replace_malloc.c:153) > ==12826== by 0x402E9086: __cxa_get_globals (in > /usr/lib/libstdc++.so.5.0.3) > ==12826== by 0x402E9CFD: __cxa_throw (in > /usr/lib/libstdc++.so.5.0.3) > ==12826== by 0x80490D8: main (in > /home/avangel/test/exc/a.out) > ==12826== by 0x40326A06: __libc_start_main (in > /lib/i686/libc-2.3.2.so) > ==12826== by 0x8048F9C: ??? (start.S:81) Do you mean this? This just says that the exception throw allocated some memory, and it was never freed - but it isn't lost, because there's still a pointer to it (maybe it would get recycled with another exception?). This is shown because you used --show-reachable=yes; without that, it would only show definite and possible leaks. J |
|
From: Dirk M. <dm...@gm...> - 2003-10-22 16:56:50
|
On Wednesday 22 October 2003 17:21, Attila wrote: > I got warning to the simple code below (exc.cpp) if I link > the pthread library like don't use --show-reachable=yes if you don't know what it means. |