私は自分のより大きなプログラムの問題を実証するためにテストケースプログラムを書いてきましたが、テストケースには元のプログラムにはないバグがあります。
ヘッダーファイルは次のとおりです。
// compiled with g++ -I/usr/local/bin/boost_1_43_0 -Wall -std=c++0x -g test.cpp
#include <bitset>
#include <boost/shared_ptr.hpp>
#include <vector>
typedef std::vector< std::vector< std::bitset<11> > > FlagsVector;
namespace yarl
{
    namespace path
    {
        class Pathfinder;
    }
    namespace level
    {
        class LevelMap
        {
        // Member Variables
            private:
                int width, height;
                FlagsVector flags;
            public:
                boost::shared_ptr<path::Pathfinder> pathfinder;
        // Member Functions
            LevelMap(const int, const int);
            int getWidth() const {return width;}
            int getHeight() const {return height;}
            bool getFifthBit(const int x, const int y) const
            {
                return flags.at(x).at(y).test(5);
            }
        };
        class Level
        {
        // Member Variables
            public:
                LevelMap map;
        // Member Functions
            public:
                Level(const int w=50, const int h=50);
        };
    }
    namespace path
    {
        class Pathfinder
        {
        // Member Variables
            private:
                boost::shared_ptr<level::LevelMap> clientMap;
        // Member Functions
            public:
                Pathfinder() {}
                Pathfinder(level::LevelMap* cm)
                : clientMap(cm) {}
                void test() const;
        };
    }
}
実装ファイルは次のとおりです。
#include <iostream>
#include "test.hpp"
using namespace std;
namespace yarl
{
    namespace level
    {
        LevelMap::LevelMap(const int w, const int h)
        : width(w), height(h), flags(w, vector< bitset<11> >(h, bitset<11>())),
          pathfinder(new path::Pathfinder(this)) 
        {}
        Level::Level(const int w, const int h)
        : map(w,h)
        {
            map.pathfinder->test();
        }
    }
    namespace path
    {
        void Pathfinder::test() const
        {
            int width = clientMap->getWidth();
            int height = clientMap->getHeight();
            cerr << endl;
            cerr << "clientMap->width: " << width << endl; 
            cerr << "clientMap->height: " << height << endl; 
            cerr << endl;
            for(int x=0; x<width; ++x)
            {
                for(int y=0; y<height; ++y)
                {
                    cerr << clientMap->getFifthBit(x,y);
                }
                cerr << "***" << endl; // marker for the end of a line in the output
            }
        }
    }
}
int main()
{
    yarl::level::Level l;
    l.map.pathfinder->test();
}
このプログラムを電気柵にリンクすると、実行すると次のエラーで中止されます。
ElectricFence Aborting: free(bffff434): address not from malloc().
Program received signal SIGILL, Illegal instruction.
0x0012d422 in __kernel_vsyscall ()
gdbからのバックトレースは、不正な命令がコンパイラによって生成されたのデストラクタにあることを示していPathfinderます。これは、shared_ptrの破棄に問題があります。誰もがそれがなぜであるかわかりますか?