Menu

#20 Memory leak

v1.0 (example)
open
nobody
None
5
2014-07-02
2013-09-13
Roman Ronge
No

Look at the lines 419-420 and 450-451 in rapidxml.hpp version 1.13. Both sections allocate from pool (not really used) which is later released but also using new operator which is never deleted. I think this is just oversight but needs to be fixed.

Related

Bugs: #20

Discussion

  • Tobias

    Tobias - 2013-10-14

    These 2 lines are in question right?
    void memory = allocate_aligned(sizeof(xml_node<Ch>));
    xml_node<Ch>
    node = new(memory) xml_node<Ch>(type);

    Is new in this case actually allocating memory, doesnt it just initialize xml_node at a preallocated location?

     
  • Roman Ronge

    Roman Ronge - 2013-10-14

    Hi Tobias,

    The new operator actually allocates memory. Since it is not paired with any delete later on, the memory is never released. You would need to override the global new operator for your xml_node and xml_attribute classes to use your own memory pool. If you just want to initialize the memory allocated from the pool, use memset as I did and set the init values as per your constructors.

    RR

    From: Tobias [mailto:tobbjo@users.sf.net]
    Sent: Monday, October 14, 2013 4:36 AM
    To: [rapidxml:bugs]
    Subject: [rapidxml:bugs] #20 Memory leak

    These 2 lines are in question right?
    void memory = allocate_aligned(sizeof(xml_node));
    xml_node node = new(memory) xml_node(type);

    Is new in this case actually allocating memory, doesnt it just initialize xml_node at a preallocated location?


    [bugs:#20]http://sourceforge.net/p/rapidxml/bugs/20/ Memory leak

    Status: open
    Created: Fri Sep 13, 2013 05:44 PM UTC by Roman Ronge
    Last Updated: Fri Sep 13, 2013 05:44 PM UTC
    Owner: nobody

    Look at the lines 419-420 and 450-451 in rapidxml.hpp version 1.13. Both sections allocate from pool (not really used) which is later released but also using new operator which is never deleted. I think this is just oversight but needs to be fixed.


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/rapidxml/bugs/20/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #20

  • Tobias

    Tobias - 2013-10-14

    This is from cplusplus.com
    new (p2) MyClass;
    // does not allocate memory -- calls: operator new (sizeof(MyClass),p2)
    // but constructs an object at p2

    This is from good old Borland:
    static inline void * _RTLENTRY operator new(size_t, void* ptr) _RWSTD_THROW_SPEC_NULL
    { return ptr; }

    But if you have verified that the function eats memory I will not argue that it does not. I have not seen any memory leaks though.

    Regards
    Tobias

     
  • Roman Ronge

    Roman Ronge - 2013-10-14

    Maybe it was the VC++ 2008 compiler doing this, not recognizing this type of syntax properly. I don't know. It certainly was a cause of our memory leak in program where we read and process 20k xml file every 5 seconds - blowing PC memory overnight and putting it into "low memory situation". Subsequently, all allocation failed that even the allocation you have in xml_memorypool ( allocate_aligned) failed and on top of that, didn't throw any exception and just returned null pointer. You can imagine the consequences.

    As much as I like shortcuts too, I would be more explicit in what I want code to do - portability will always be an issue. Perhaps using new operator is it was used in this case is one of them. Regardless of what C++ standards say.

    RR

    From: Tobias [mailto:tobbjo@users.sf.net]
    Sent: Monday, October 14, 2013 10:05 AM
    To: [rapidxml:bugs]
    Subject: [rapidxml:bugs] #20 Memory leak

    This is from cplusplus.com
    new (p2) MyClass;
    // does not allocate memory -- calls: operator new (sizeof(MyClass),p2)
    // but constructs an object at p2

    This is from good old Borland:
    static inline void * _RTLENTRY operator new(size_t, void* ptr) _RWSTD_THROW_SPEC_NULL
    { return ptr; }

    But if you have verified that the function eats memory I will not argue that it does not. I have not seen any memory leaks though.

    Regards
    Tobias


    [bugs:#20]http://sourceforge.net/p/rapidxml/bugs/20/ Memory leak

    Status: open
    Created: Fri Sep 13, 2013 05:44 PM UTC by Roman Ronge
    Last Updated: Mon Oct 14, 2013 08:36 AM UTC
    Owner: nobody

    Look at the lines 419-420 and 450-451 in rapidxml.hpp version 1.13. Both sections allocate from pool (not really used) which is later released but also using new operator which is never deleted. I think this is just oversight but needs to be fixed.


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/rapidxml/bugs/20/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

     

    Related

    Bugs: #20

  • Bernd

    Bernd - 2014-07-02

    VC 2008 know placements new.
    Also STL is using it and a lot of other contrainer-frameworks.
    I never encountered a memeory leak with it.

    I am working aleady 8 years with a framework that use this concept massivly.

    RapidXML is a header-only software. So the generated code depends on what you include before this header. With some c++ magic you can break everything - like defining some global new operators...
    But this is not on issue of rapidXML.

     

Log in to post a comment.