tags:

views:

55

answers:

0

I'm porting some old C++ project on Linux (RHEL 5.3) and, therefore need to obtain all the binaries on RHEL 5.3. The result should be in the end several libraries + the executable.

I have some dependencies from several 3rd parties. My project libraries have dependencies as some of the 3rd party libraries.

My library MyLib depends My3rdPartyLib.

I'm getting a memory fault error.

I have installed valgrind to get more details.

// this is from the My3rdPartyLib where I have only the header source + so file
class My3rdPartyClass
{
public:
  My3rdPartyClass() {}
  My3rdPartyClass(int id, int nInstance, uint4 offset, ThirdPartyEnumType::TYPE_ENUM type, AnotherThirdPartyEnumType::DB_TYPE dbType) :
   id(id),
   nInstance(nInstance),
   offset(offset),
   type(type),
   dbType(dbType),
   len(0) {}
  My3rdPartyClass(int id, int nInstance, uint4 offset, ThirdPartyEnumType::TYPE_ENUM type, uint4 len, AnotherThirdPartyEnumType::DB_TYPE dbType) :
   id(id),
   nInstance(nInstance),
   offset(offset),
   type(type),
   dbType(dbType),
   len(len) {}

   int   id;
   int  nInstance;
   uint4 offset;
   ThirdPartyEnumType::TYPE_ENUM type;
   AnotherThirdPartyEnumType::DB_TYPE dbType;
   uint4 len;
};


//this is code from my library MyLib 
void MyClass_FACTORY::buildMyMap()
{
    MyClass::mapAttr=new map<string, My3rdPartyClass>;
    (*MyClass::mapAttr)["myKey"]=My3rdPartyClass(MyClass::myAtrribute,1,0,enumValueCorrespondentToString,40,enumValue);
}

This return a memory fault issue.

 - ObjectClass3rdParty_FACTORY_LIST is part of My3rdPartyLib 
 - MyClass_FACTORY is part of MyLib 
  Valgrind says (please see bellow)

==22518== Invalid read of size 8
==22518==    at 0x83B6293: std::_Rb_tree<std::string, std::pair<std::string const, AttributeDef>, std::_Select1st<std::pair<std::string const, AttributeDef> >, std::less<std::string>, std::allocator<std::pair<std::string const, AttributeDef> > >::lower_bound(std::string const&) (stl_tree.h:648)
==22518==    by 0xA43C052: MyClass_FACTORY::buildMyMap() (stl_map.h:576)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)
==22518==  Address 0x13480238 is 3 bytes after a block of size 29 alloc'd
==22518==    at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==22518==    by 0x381909B800: std::string::_Rep::_S_create(unsigned long, unsigned long, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)
==22518==    by 0x381909C304: (within /usr/lib64/libstdc++.so.6.0.8)
==22518==    by 0x381909C4B1: std::string::string(char const*, std::allocator<char> const&) (in /usr/lib64/libstdc++.so.6.0.8)
==22518==    by 0xA43C044: MyClass_FACTORY::buildMyMap() (nodempmScp.pc:3156)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)
==22518==
==22518== Invalid read of size 8
==22518==    at 0xA43C085: MyClass_FACTORY::buildMyMap() (basic_string.h:591)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)
==22518==  Address 0x134801A8 is 16 bytes before a block of size 48 alloc'd
==22518==    at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==22518==    by 0xA43BFF6: MyClass_FACTORY::buildMyMap() (nodempmScp.pc:3151)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)
==22518==
==22518== Invalid write of size 4
==22518==    at 0xA43C116: MyClass_FACTORY::buildMyMap() (nodempmScp.pc:3156)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)
==22518==  Address 0x134801F4 is 12 bytes after a block of size 48 alloc'd
==22518==    at 0x4A06019: operator new(unsigned long) (vg_replace_malloc.c:167)
==22518==    by 0xA43BFF6: MyClass_FACTORY::buildMyMap() (nodempmScp.pc:3151)
==22518==    by 0x7C9DD61: ObjectClass3rdParty_FACTORY_LIST::buildMyMap() (object.h:256)
==22518==    by 0x7B4B4D7: main (initprocess.cxx:44)

What I tested so far :

  • if I do a map of key-type string (std::string) and value-type string I can add an element to to the map without any issue

  • if I bring a similar class to My3rdPartyClass into MyLib (exactly the same structure, just a different name) adding an element to a map of key-type string (std::string) and value-type MyCopyOfMy3rdPartyClass it works....

To my surprise :

a ldd executed to MyLib.so  
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ad35dae2000)
        librt.so.1 => /lib64/librt.so.1 (0x00002ad35dcfd000)
        **libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00002ad35df06000)**
        libm.so.6 => /lib64/libm.so.6 (0x00002ad35e207000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002ad35e48a000)
        libc.so.6 => /lib64/libc.so.6 (0x00002ad35e698000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003816000000)

as opposed to a ldd executed on My3rdPartyLib.so

libpthread.so.0 => /lib64/libpthread.so.0 (0x00002ac7e4110000)
librt.so.1 => /lib64/librt.so.1 (0x00002ac7e432b000)
**libstdc++.so.5 => /usr/lib64/libstdc++.so.5 (0x00002ac7e4534000)**
libm.so.6 => /lib64/libm.so.6 (0x00002ac7e4810000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00002ac7e4a93000)
libc.so.6 => /lib64/libc.so.6 (0x00002ac7e4ca1000)
/lib64/ld-linux-x86-64.so.2 (0x0000003816000000)

Could this strange behavior be caused by libstdc++.so.6 used by MyLib as opposed to libstdc++.so.5 used by My3rdPartyLib?

dev>rpm -qf /usr/lib64/libstdc++.so.6
libstdc++-4.1.2-44.el5
dev>rpm -qf /usr/lib64/libstdc++.so.5
compat-libstdc++-33-3.2.3-61

dev>rpm -qa | grep gcc
libgcc-4.1.2-44.el5
gcc-c++-4.1.2-44.el5
libgcc-4.1.2-44.el5
gcc-4.1.2-44.el5
compat-gcc-34-3.4.6-4
compat-gcc-34-c++-3.4.6-4

Many thanks for your help.