STL Memory Leak when compiling on11.00 HPUX using the aCC -AA flag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy Lemaire

    STL Memory Leak when compiling on11.00 HPUX using the aCC -AA flag

    Hello,

    I am working on cross platform code that is displaying a huge memory
    leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not
    leaking on NT, LINUX, Solaris, or HPUX without the -AA flag. In
    another news group I came across some interesting (ok scarey)
    information regarding memory leaks in the STL list<...> container. I
    have compiled and executed the following code and verified that this
    does in fact leak on my system.

    #include "stdio.h"
    #include "stdlib.h"
    #include "malloc.h"

    #include <list>
    using namespace std;
    template class list<int>;

    int main (int argc, char *argv[])
    {
    list<int> list_int;
    char c='r';

    do
    {
    for ( int j = 0; j < 99999 ; j++ )
    {
    list_int.push_b ack(2);
    list_int.pop_fr ont();
    }

    printf ( "\nPress r to repeat, q to exit\n=>" );
    c = getchar ();
    }
    while ( c != 'q' );

    return 0;
    }

    STL is used throughout my code. Has anyone run into this problem? If
    so could you please let me know if you have come up with a fix, patch,
    or work-around. Any help would be greatly appreciated.

    Regards,
    Jeremy
  • Ivan Vecerina

    #2
    Re: STL Memory Leak when compiling on11.00 HPUX using the aCC -AA flag

    "Jeremy Lemaire" <jlemaire@xl.co m> wrote in message
    news:8a33fb62.0 310091322.41de1 af@posting.goog le.com...
    ....[color=blue]
    > I am working on cross platform code that is displaying a huge
    > memory leak when compiled on 11.00 HPUX using the aCC -AA flag.[/color]
    Question: what does the -AA flag do, what do you need it for?
    ....[color=blue]
    > I have compiled and executed the following code and verified
    > that this does in fact leak on my system.[/color]
    ....[color=blue]
    > for ( int j = 0; j < 99999 ; j++ )
    > {
    > list_int.push_b ack(2);
    > list_int.pop_fr ont();
    > }[/color]
    ....[color=blue]
    > STL is used throughout my code. Has anyone run into this problem? If
    > so could you please let me know if you have come up with a fix, patch,
    > or work-around. Any help would be greatly appreciated.[/color]

    What is the magnitude of the memory leak that you are observing?

    The code you have posted should not leak any memory if
    the std::list container is decently implemented.
    If it does leak memory on your platform, can you step
    through the code with a debugger and analyze where the
    leak comes from ?

    If it is a problem with the implementation of the standard
    library that you are using, maybe using an alternative
    implementation such as the free STLport (www.stlport.org)
    will help.


    Anyway, this is not a problem with standard C++ (as it is
    specific to a platform and a given compiler setting).
    You may want to request support in a forum dedicated
    to the compiler you are using.

    Regards,
    Ivan
    --
    Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



    Comment

    • Jeremy Lemaire

      #3
      Re: STL Memory Leak when compiling on11.00 HPUX using the aCC -AA flag

      "Ivan Vecerina" <ivecATmyrealbo xDOTcom> wrote in message news:<3f85d877@ news.swissonlin e.ch>...[color=blue]
      > "Jeremy Lemaire" <jlemaire@xl.co m> wrote in message
      > news:8a33fb62.0 310091322.41de1 af@posting.goog le.com...
      > ...[color=green]
      > > I am working on cross platform code that is displaying a huge
      > > memory leak when compiled on 11.00 HPUX using the aCC -AA flag.[/color]
      > Question: what does the -AA flag do, what do you need it for?[/color]

      JL->Thanks for the quick response Ivan. This is from HP:

      Description:
      The new -AA command line option enables use of the new 2.0 Standard
      C++ Library, which includes the new standard conforming
      ("templatize d") iostream library. This is the first release of the 2.0
      library. It conforms to the ISO C++ standard.
      [color=blue]
      > ...[color=green]
      > > I have compiled and executed the following code and verified
      > > that this does in fact leak on my system.[/color]
      > ...[color=green]
      > > for ( int j = 0; j < 99999 ; j++ )
      > > {
      > > list_int.push_b ack(2);
      > > list_int.pop_fr ont();
      > > }[/color]
      > ...[color=green]
      > > STL is used throughout my code. Has anyone run into this problem? If
      > > so could you please let me know if you have come up with a fix, patch,
      > > or work-around. Any help would be greatly appreciated.[/color]
      >
      > What is the magnitude of the memory leak that you are observing?[/color]

      JL->The software is used in a Call Processing environment and varies
      according to call volume. The more messages processed with STL
      containers the bigger the leak. In general 7-10 calls per second will
      leak 2500 kbytes per hour at a constant rate until the process runs
      out of memory and core dumps.
      [color=blue]
      >
      > The code you have posted should not leak any memory if
      > the std::list container is decently implemented.
      > If it does leak memory on your platform, can you step
      > through the code with a debugger and analyze where the
      > leak comes from ?[/color]

      JL->Here is the gdb output:

      (gdb) where
      #0 0x4b68 in std::list<int,s td::allocator<i nt>>::insert
      (this=0x7f7f092 0,
      #aggretxform#77 =@0x7f7f0950,
      __it={<struct std::iterator<s td::bidirection al_iterator_tag ,int,long,int
      *,int &>> = {<No data fields>}, _C_node = 0x40004cd8},
      __x=@0x7f7f0940 )
      at /opt/aCC/include_std/list:911
      #1 0x4404 in main (argc=1, argv=0x7f7f076c ) at leakcode.cpp:18
      (gdb) display this
      2: this = (class std::list<int,s td::allocator<i nt> > *) 0x7f7f0920

      But I am not sure how this will help. Should I attempt to modify the
      std:list class?
      [color=blue]
      >
      > If it is a problem with the implementation of the standard
      > library that you are using, maybe using an alternative
      > implementation such as the free STLport (www.stlport.org)
      > will help.[/color]

      JL->Good idea, the only problem is that I only have until the end of
      today to resolve this. I was hoping for a quick fix like a patch or
      adding a flag to the build line. I know, wishfull thinking.
      [color=blue]
      >
      >
      > Anyway, this is not a problem with standard C++ (as it is
      > specific to a platform and a given compiler setting).
      > You may want to request support in a forum dedicated
      > to the compiler you are using.[/color]

      JL->I tried one of the compiler forums and they refered me here.
      Thanks again for the help.
      [color=blue]
      >
      > Regards,
      > Ivan[/color]

      Comment

      • Ivan Vecerina

        #4
        Re: STL Memory Leak when compiling on11.00 HPUX using the aCC -AA flag

        Hi Jeremy,[color=blue]
        > "Ivan Vecerina" <ivecATmyrealbo xDOTcom> wrote in message[/color]
        news:<3f85d877@ news.swissonlin e.ch>...
        .... (thanks for the info) ....[color=blue][color=green]
        > > The code you have posted should not leak any memory if
        > > the std::list container is decently implemented.
        > > If it does leak memory on your platform, can you step
        > > through the code with a debugger and analyze where the
        > > leak comes from ?[/color][/color]
        ....[color=blue]
        > But I am not sure how this will help. Should I attempt to modify the
        > std:list class?[/color]
        Well, it is only an option if you are sure that you understand its
        implementation very well.
        Its code would need to be carefully reviewed and understood...
        [color=blue][color=green]
        > > If it is a problem with the implementation of the standard
        > > library that you are using, maybe using an alternative
        > > implementation such as the free STLport (www.stlport.org)
        > > will help.[/color]
        >
        > JL->Good idea, the only problem is that I only have until the end of
        > today to resolve this. I was hoping for a quick fix like a patch or
        > adding a flag to the build line. I know, wishfull thinking.[/color]

        A possible workaround, if you are only using the std::list as
        a queue, would be to replace this broken container with an
        std::deque -- which also has the push_back/pop_front members.
        [color=blue][color=green]
        > > Anyway, this is not a problem with standard C++ (as it is
        > > specific to a platform and a given compiler setting).
        > > You may want to request support in a forum dedicated
        > > to the compiler you are using.[/color]
        >
        > JL->I tried one of the compiler forums and they refered me here.[/color]

        Well, all I can say is that the code sample you posted
        should not leak any memory according to the C++ standard.
        I would say that the standard library implementation
        you use has a bug if this is steadily leaking memory.

        [NB: btw, however, the following includes are incorrect
        according to the C++ standard:
        #include "stdio.h"
        #include "stdlib.h"
        #include "malloc.h"
        This should be:
        #include <cstdio>
        #include <cstdlib>
        // and malloc is defined in cstdlib already
        ]
        [color=blue]
        > Thanks again for the help.[/color]

        Sorry I can't help further...

        Sincerely,
        Ivan
        --
        Ivan Vecerina - expert in medical devices, software - info, links, contact information, code snippets



        Comment

        Working...