I've been working with gcc 4.6 with C++ doing some templates exercises

I seem to have some unexplained behavior which might be a bug, or maybe
I'm ignorant.

First - let me give you a link for my code

http://www.nylxs.com/docs/linklist.tgz

gcc version

ruben@www2:~> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-suse-linux/4.6/lto-wrapper
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib
--with-system-zlib --enable-__cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.6
--enable-linux-futex --without-system-libunwind
--with-plugin-ld=/usr/bin/gold --with-arch-32=i586 --with-tune=generic
--build=i586-suse-linux
Thread model: posix
gcc version 4.6.0 20110415 [gcc-4_6-branch revision 172496] (SUSE Linux) 




specifically, I wrote a program to test my templates that create a
linked list class. There is a simple library to do some statistics on the list
members. It is doing a double delete core dump in a section of code that
I see no reason for a destructor call. It didn't do this for a simpler
version of the template argument call.

ddd ./test_del2
test_del2.cpp:84

79 for( i=0; i < 100; ++i){
80 std::cout << "index " << i << "-------------------------------
\n";
81 tally = new chainlist::List<stats::Distribution<int> >;
82 stats::take_tally<int>(a[i], tally );
83 std::cout << "Creating Tally " << std::endl;
84 tallies->insert(*tally);
85 std::cout << "inserted population figures for index " << i <<
"-------------------------------\n";
86 delete tally;
87
88 //visual inspection of population data to make sure the resiults work
89 // std::cout << "visual inspection of population data to make sure
the results work" << std::endl;

breaking on line 84 and the stepping through

263 void List<T>::insert ( T val )
264 {
265 if(!front()){
266 Node<T> * tmp = new Node<T>(val);
267 front(tmp);
268 endd(tmp);
269 cursor(tmp);
270 sizeup();
271 return;
272 }else{
273 Node<T> * tmp = new Node<T>(val, endd());
274 // endd()->next(tmp); // redundant
275 endd(tmp);
276 cursor(tmp);
277 sizeup();
278 return;
279 }
280 } /* --- end of method List<T>::insert ----

/home/ruben/cplus/link_list_template_mysql/linklist.h:265
is the next line

on line 266 is where it seems to be doing weird stuff

home/ruben/cplus/link_list_template_mysql/linklist.h:266

it calls the correct constructor for the node object
/home/ruben/cplus/link_list_template_mysql/linklist.h:82
81 Node<unk>::Node(unk val, Node<unk> *item_to_link_to){
82 value(val);
83 if(!item_to_link_to){
84 next_ = 0;
85 }
86
87 else{
88 next(item_to_link_to->next());
89 item_to_link_to->next(this);
90 }
91 }

I the calls the accessory method value() from the list class

108 }
109
110 template<class unk>
111 void Node<unk>::value(unk val){
112 value_ = new unk(val);
113 }
114
/home/ruben/cplus/link_list_template_mysql/linklist.h:112

it returns nomally

81 Node<unk>::Node(unk val, Node<unk> *item_to_link_to){
82 value(val);
83 if(!item_to_link_to){
84 next_ = 0;
85 }
86
87 else{
88 next(item_to_link_to->next());
89 item_to_link_to->next(this);
90 }
91 }
92 chainlist::Node<chainlist::List<stats::Distribution<int> > >::Node
(this=0x809f488, val=..., item_to_link_to=0x0) at
/home/ruben/cplus/link_list_template_mysql/linklist.h:83


then it calls for the List destructor, I have no idea way

373 template<class T>
374 List<T>::~List<T>(){
375 remove_all();
376 // std::cout << "Deleted All*************" << __LINE__ << std::endl;
377 }
378
(gdb) ptype List
Type chainlist::List<stats::Distribution<int> > has no component named
List.
(gdb) *** glibc detected ***
/home/ruben/cplus/link_list_template_mysql/test_del2: double free or
corruption (out): 0x0809f460 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7d9150b]
/lib/libc.so.6[0xb7d92de4]
/lib/libc.so.6(cfree+0x6d)[0xb7d95fdd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x1f)[0xb7f7c87f]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x804b4a4]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x804b2c6]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x804aa30]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x804987d]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x80498f0]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x8048d42]
/lib/libc.so.6(__libc_start_main+0xfe)[0xb7d3aace]
/home/ruben/cplus/link_list_template_mysql/test_del2[0x8048961]
======= Memory map: ========
08048000-0804d000 r-xp 00000000 08:12 270203586
/home/ruben/cplus/link_list_template_mysql/test_del2
0804d000-0804e000 r--p 00004000 08:12 270203586
/home/ruben/cplus/link_list_template_mysql/test_del2
0804e000-0804f000 rw-p 00005000 08:12 270203586
/home/ruben/cplus/link_list_template_mysql/test_del2
0804f000-080b2000 rw-p 00000000 00:00 0 [heap]
b7c00000-b7c21000 rw-p 00000000 00:00 0
b7c21000-b7d00000 ---p 00000000 00:00 0
b7d22000-b7d24000 rw-p 00000000 00:00 0
b7d24000-b7e7d000 r-xp 00000000 08:02 36311 /lib/libc-2.10.1.so
b7e7d000-b7e7e000 ---p 00159000 08:02 36311 /lib/libc-2.10.1.so
b7e7e000-b7e80000 r--p 00159000 08:02 36311 /lib/libc-2.10.1.so
b7e80000-b7e81000 rw-p 0015b000 08:02 36311 /lib/libc-2.10.1.so
b7e81000-b7e84000 rw-p 00000000 00:00 0
b7e84000-b7ea0000 r-xp 00000000 08:02 910019 /lib/libgcc_s.so.1
b7ea0000-b7ea1000 r--p 0001b000 08:02 910019 /lib/libgcc_s.so.1
b7ea1000-b7ea2000 rw-p 0001c000 08:02 910019 /lib/libgcc_s.so.1
b7ea2000-b7ec9000 r-xp 00000000 08:02 36319 /lib/libm-2.10.1.so
b7ec9000-b7eca000 r--p 00027000 08:02 36319 /lib/libm-2.10.1.so
b7eca000-b7ecb000 rw-p 00028000 08:02 36319 /lib/libm-2.10.1.so
b7ecb000-b7faf000 r-xp 00000000 08:02 348377
/usr/lib/libstdc++.so.6.0.16
b7faf000-b7fb3000 r--p 000e3000 08:02 348377
/usr/lib/libstdc++.so.6.0.16
b7fb3000-b7fb4000 rw-p 000e7000 08:02 348377
/usr/lib/libstdc++.so.6.0.16
b7fb4000-b7fbb000 rw-p 00000000 00:00 0
b7fde000-b7fe0000 rw-p 00000000 00:00 0
b7fe0000-b7ffe000 r-xp 00000000 08:02 36304 /lib/ld-2.10.1.so
b7ffe000-b7fff000 r--p 0001d000 08:02 36304 /lib/ld-2.10.1.so
b7fff000-b8000000 rw-p 0001e000 08:02 36304 /lib/ld-2.10.1.so
bffeb000-c0000000 rw-p 00000000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]

Program received signal SIGABRT, Aborted.
0xffffe430 in __kernel_vsyscall ()
(gdb) delete 7
(gdb)


I've rattled my brain on this and can't explain it ..


BTW bugzilla is dead....


-- 
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like 
Atlantis, reaches mythological proportions in the mind of the world  - RI Safir 
1998

http://fairuse.nylxs.com  DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our 
own cultural heritage -- we need the ability to participate in our own society."

"> I'm an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been 
attached at the hip since the 1st dynasty in Ancient Egypt.  I guess you missed 
that one."

© Copyright for the Digital Millennium

Reply via email to