sigbus while storing pointers in a stl map

The following stacktrace shows the place where my code crashes with a sigbus.
I highlight the validity of an object (a pointer, in this case) being stored in the stl map
throughout the calls. This happens when I try to insert a new pair into the map.

The sigbus happens once in a while in a very specific machine (it does not happen at all if I run
in a different machine). In this particular machine we have installed: gcc version 4.1.1
20060525 (Red Hat 4.1.1-1).

1
2
3
4
5
6
7
8
9
10
11
12
13
(gdb) where

#0  std::_Rb_tree<Object*, std::pair<Object* const, double>, std::_Select1st<std::pair<Object* const, double> >, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::_M_insert (
    this=0x10058ca78, __x=0x4072b6, __p=0x7fffffa4bec0, __v=@0x5864b0) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:813
#1  0x000000000040d71b in std::_Rb_tree<Object*, std::pair<Object* const, double>, std::_Select1st<std::pair<Object* const, double> >, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::insert_unique (this=0x586570, __position={_M_node = 0x5865f0}, __v=@0x7fffffa4c010) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:957
#2  0x000000000040d9c9 in std::map<Object*, double, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::insert (this=0x586570, position={_M_node = 0x5865f0}, __x=@0x7fffffa4c010)
    at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:420
#3  0x000000000040da7a in std::map<Object*, double, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::operator[] (this=0x586570, __k=@0x58be68)
    at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:348
#4  0x0000000000403f3f in LosslessMuSampled2::add (this=0x5152e0, gp=13, parent=0x58cbb0, children=@0x58caf0) at LosslessMuSampled2.h:107
#5  0x000000000040454a in SLLosslessSamplerConsistent::coreSampling (this=0x5152b0, start=@0x7fffffa4c240, gp=13, parentBlank=3, parentMovedTile=3, op=1, lookahead=0) at SLLosslessSamplerConsistent.h:122
#6  0x0000000000404876 in SLLosslessSamplerConsistent::sample (this=0x5152b0, start=@0x7fffffa4c240, lookahead=0) at SLLosslessSamplerConsistent.h:102
#7  0x00000000004054f0 in main (argc=7, argv=0x7fffffa4c5f8) at MainSlidingTileSampler.cpp:122 


From frame 3 to frame 0 we are inside stl code. So lets look at frame 2.

1
2
3
4
5
6
7
8
9
10
11
(gdb) frame 2
#2  0x000000000040d9c9 in std::map<Object*, double, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::insert (this=0x586570, position={_M_node = 0x5865f0}, __x=@0x7fffffa4c010)
    at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h:420
420     /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h: No such file or directory.
        in /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_map.h
(gdb) p __x
$77 = (const std::pair<Object* const,double> &) @0x7fffffa4c010: {first = 0x58c9b0, second = 0}
(gdb) p __x.first
$78 = (Object * const) 0x58c9b0
(gdb) p *$78
$79 = {features = 0x58cb90, h = 11, p = 12, static size = 2}


The object seems to be fine in frame 2 and features is still pointing to something meaningful:
features = 0x58cb90

1
2
3
4
5
6
7
8
9
10
(gdb) frame 1
#1  0x000000000040d71b in std::_Rb_tree<Object*, std::pair<Object* const, double>, std::_Select1st<std::pair<Object* const, double> >, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::insert_unique (this=0x586570, __position={_M_node = 0x5865f0}, __v=@0x7fffffa4c010) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:957
957     /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h: No such file or directory.
        in /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h
(gdb) p __v
$80 = (const std::pair<Object* const,double> &) @0x7fffffa4c010: {first = 0x58c9b0, second = 0}
(gdb) p __v.first
$81 = (Object * const) 0x58c9b0
(gdb) p *$81
$82 = {features = 0x58cb90, h = 11, p = 12, static size = 2}


In frame 1 we are still good with the object. Lets look at frame 0 now.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
(gdb) frame 0
#0  std::_Rb_tree<Object*, std::pair<Object* const, double>, std::_Select1st<std::pair<Object* const, double> >, CompareObjectsGPP, std::allocator<std::pair<Object* const, double> > >::_M_insert (
    this=0x10058ca78, __x=0x4072b6, __p=0x7fffffa4bec0, __v=@0x5864b0) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h:813
813     in /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/bits/stl_tree.h
(gdb) p __x
$83 = (std::_Rb_tree_node_base *) 0x4072b6
(gdb) p __p
$84 = (std::_Rb_tree_node_base *) 0x7fffffa4bec0
(gdb) p __v
$85 = (const std::pair<Object* const,double> &) @0x5864b0: {first = 0x586490, second = 2.5463949498006121e-313}
(gdb) p $85.first
$86 = (Object * const) 0x586490
(gdb) p *$86
$87 = {features = 0x10001, h = 0, p = 0, static size = 2}


The object (Object * const) seems to be pointing to something invalid now and features has a
spooky value. At this point the program crashes with a sigbus. I can't see anything else to be
causing the sigbus but the object (Object * const). Is this a problem of storing pointers in a stl
container? I can't see this being a mistake I made as the object is fine when I ask to insert it
into the map.

I thought I could store pointers in stl containers as long as I managed the memory properly. But
apparently this stacktrace is showing me that even when I do the job properly something odd
might happen.

Any thoughts?






Last edited on
Topic archived. No new replies allowed.