Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. very strange memory problem ....please help

very strange memory problem ....please help

Scheduled Pinned Locked Moved C / C++ / MFC
helpwcflinuxxml
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dharani
    wrote on last edited by
    #1

    Hello all Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go .. We have a class which has members listed as below in the declaration class SOAP_CMAC MyUserProfile { public: std::string name; std::string name2; std::string firstName; public: LONG64 pwdStatus; std::string setType; public: class NotifyOptions *mNotifyOptions; LONG64 USCOREtype; std::string USCOREmacAddress; std::string USCOREipAddress; public: MyUserProfile() { } virtual ~MyUserProfile() { } }; In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault! The lines which crash due to segmentation fault are doing an assign operation USCOREmacAddress.assign(“char string”); But reference to std::strings name , name2 , firstName and settype do not crash . Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it … The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations …. Any help guys on this problem ? with warm regards

    redindian

    H K T D 4 Replies Last reply
    0
    • D dharani

      Hello all Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go .. We have a class which has members listed as below in the declaration class SOAP_CMAC MyUserProfile { public: std::string name; std::string name2; std::string firstName; public: LONG64 pwdStatus; std::string setType; public: class NotifyOptions *mNotifyOptions; LONG64 USCOREtype; std::string USCOREmacAddress; std::string USCOREipAddress; public: MyUserProfile() { } virtual ~MyUserProfile() { } }; In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault! The lines which crash due to segmentation fault are doing an assign operation USCOREmacAddress.assign(“char string”); But reference to std::strings name , name2 , firstName and settype do not crash . Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it … The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations …. Any help guys on this problem ? with warm regards

      redindian

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      If you are not getting any additional warning messages from the compiler with 2.6, then I would check to make sure that all modules were being compiled with the new 2.6 library. Delete all the object modules first if you have to.

      Best wishes, Hans


      [Hans Dietrich Software]

      1 Reply Last reply
      0
      • D dharani

        Hello all Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go .. We have a class which has members listed as below in the declaration class SOAP_CMAC MyUserProfile { public: std::string name; std::string name2; std::string firstName; public: LONG64 pwdStatus; std::string setType; public: class NotifyOptions *mNotifyOptions; LONG64 USCOREtype; std::string USCOREmacAddress; std::string USCOREipAddress; public: MyUserProfile() { } virtual ~MyUserProfile() { } }; In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault! The lines which crash due to segmentation fault are doing an assign operation USCOREmacAddress.assign(“char string”); But reference to std::strings name , name2 , firstName and settype do not crash . Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it … The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations …. Any help guys on this problem ? with warm regards

        redindian

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        class NotifyOptions *mNotifyOptions; this is only a pointer, which got to get assigned to an object to work with. As mNotifyOptions = new NotifyOptions(); in such strange cases you should watch the memory for changes :cool:

        Press F1 for help or google it. Greetings from Germany

        D 1 Reply Last reply
        0
        • K KarstenK

          class NotifyOptions *mNotifyOptions; this is only a pointer, which got to get assigned to an object to work with. As mNotifyOptions = new NotifyOptions(); in such strange cases you should watch the memory for changes :cool:

          Press F1 for help or google it. Greetings from Germany

          D Offline
          D Offline
          dharani
          wrote on last edited by
          #4

          Hi Hans Could you plesae elaborate your point ? I understand the memory will be allocated to the pointer of the class object at runtime . But why and how should it affect the adjacent std::strings ? Also the point I am wondering is that the memory of std::string comes from stack while that of mNotifyOptions is from heap . regards

          redindian

          K 1 Reply Last reply
          0
          • D dharani

            Hi Hans Could you plesae elaborate your point ? I understand the memory will be allocated to the pointer of the class object at runtime . But why and how should it affect the adjacent std::strings ? Also the point I am wondering is that the memory of std::string comes from stack while that of mNotifyOptions is from heap . regards

            redindian

            K Offline
            K Offline
            KarstenK
            wrote on last edited by
            #5

            you got to code it somewhere in your code!!! mNotifyOptions = new NotifyOptions(); Did you?

            Press F1 for help or google it. Greetings from Germany

            1 Reply Last reply
            0
            • D dharani

              Hello all Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go .. We have a class which has members listed as below in the declaration class SOAP_CMAC MyUserProfile { public: std::string name; std::string name2; std::string firstName; public: LONG64 pwdStatus; std::string setType; public: class NotifyOptions *mNotifyOptions; LONG64 USCOREtype; std::string USCOREmacAddress; std::string USCOREipAddress; public: MyUserProfile() { } virtual ~MyUserProfile() { } }; In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault! The lines which crash due to segmentation fault are doing an assign operation USCOREmacAddress.assign(“char string”); But reference to std::strings name , name2 , firstName and settype do not crash . Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it … The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations …. Any help guys on this problem ? with warm regards

              redindian

              T Offline
              T Offline
              TimothyPMoore
              wrote on last edited by
              #6

              I would do a search and see if the implementation of malloc was modified between gcc library 2.4 to 2.6. My guess is that if the implementation of malloc changed, memory could be allocated differently using 2.6 over 2.4. You may have already had a memory bug previously using 2.4 but it did not manifest itself until the memory was allocated in some different way using the new library. Apparently somewhere code is overwriting memory in your class corrupting the private contents of the strings or corrupting the internal datastructures of malloc itself. You need to watch the memory locations for the strings to narrow down when the contents of those strings become corrupted. One clarification ... do the seg faults happen only when setting the string value or anytime you use the contents of the string ?

              1 Reply Last reply
              0
              • D dharani

                Hello all Though its linux problem I thought I will give a try to my age old forum as the problem seems to be typical memory management ...ok here I go .. We have a class which has members listed as below in the declaration class SOAP_CMAC MyUserProfile { public: std::string name; std::string name2; std::string firstName; public: LONG64 pwdStatus; std::string setType; public: class NotifyOptions *mNotifyOptions; LONG64 USCOREtype; std::string USCOREmacAddress; std::string USCOREipAddress; public: MyUserProfile() { } virtual ~MyUserProfile() { } }; In the run time after object for MyUserProfile is created , reference to std::strings USCOREmacAddress and USCOREipAddress are crashing due to segmentation fault! The lines which crash due to segmentation fault are doing an assign operation USCOREmacAddress.assign(“char string”); But reference to std::strings name , name2 , firstName and settype do not crash . Upon observation I found that the line class NotifyOptions *mNotifyOptions is in between the two sections . So I moved the line class NotifyOptions *mNotifyOptions ; to the end of the class declaration . This made the reference to name , name2 , firstName , settype also to crash !!! . It seems this object mNotifyOptions which will be created at run time is somehow the reason for the crash happening on std::string objects ….But I am at wits end to know what it is and how to solve it … The point is : we migrated from gcc library 2.4. to 2.6 . And after this this problem surfaced without any modifications in the code present in both situations …. Any help guys on this problem ? with warm regards

                redindian

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                class SOAP_CMAC MyUserProfile
                {
                public:
                std::string name;
                std::string name2;
                std::string firstName;
                LONG64 pwdStatus;
                std::string setType;
                class NotifyOptions *mNotifyOptions;
                LONG64 USCOREtype;
                std::string USCOREmacAddress;
                std::string USCOREipAddress;
                MyUserProfile() { }
                virtual ~MyUserProfile() { }
                };

                void main( void )
                {
                MyUserProfile mup;
                mup.USCOREmacAddress = "1234"; <<--- this crashes?
                }

                "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups