#8 Memory leak with --help

closed-fixed
None
2
2007-02-17
2007-02-17
No

From the forum thread: https://sourceforge.net/forum/forum.php?thread_id=1675042&forum_id=261542

By: Chris (captainc_) - 2007-02-16 17:12
I get a Heap Leak every time that I use the --help switch or usage information is posted. If valid arguments are used, then there is no leak and everything runs fine. Also, I cannot create my own class to override version, failure, and usage messages as it always leads to a heap leak. I'm not sure what to do about this.

***

I found that this is happening when I call the isSet() method to test for which arguments were set due to using the xorAdd method. The weird part is that it detects the leak at this method call only when an invalid argument or --help or the like is specified. This occurs whether or not I specify my own output object.

If i specify my own output object and give it valid parameters, then a heap leak is detected on exit of the program.

Discussion

  • Daniel Aarno

    Daniel Aarno - 2007-02-17
    • priority: 5 --> 2
    • assigned_to: nobody --> macbishop
     
  • Daniel Aarno

    Daniel Aarno - 2007-02-17

    Logged In: YES
    user_id=330479
    Originator: YES

    I think this is because after displaying the help text the program will exit using the exit system call which will not invoke the dtor of the CmdLine object. This is not severe since exit frees all resources held by the process. If we want to fix this (e.g. to stop valgrind from issuing warnings) there are two approaches. Register at-exit handler that clears the resources held by the CmdLine objects (this requires keeping track of all instances) or to do an exit-by-exception. The latter is probably bad since it will break compatibility but could be considered for the future as it gives the user more control. I'll probably get around to implementing the at-exit thing since I was about to clean up some warnings anyway.

     
  • Daniel Aarno

    Daniel Aarno - 2007-02-17

    Logged In: YES
    user_id=330479
    Originator: YES

    After consideration I think this is a won't-fix. Since the "leak" only occurs as a result of program termination it is not severe and fixing it would complicate the code by requiring all members of CmdLine to be dynamically allocated. The best way would simply be to make note about this in the docs, requiring the user to dynamically allocate the CmdLine object and setting up an at-exit handler if it is really important to avoid leaks, for example to stop valgrind from complaining.

     
  • Daniel Aarno

    Daniel Aarno - 2007-02-17
    • status: open --> open-wont-fix
     
  • Daniel Aarno

    Daniel Aarno - 2007-02-17

    Logged In: YES
    user_id=330479
    Originator: YES

    I've committed a fix for this now. Given that the CmdLine and other objects are deleted correctly (i.e. by not having them on stack and deleting them in an at-exit handler) no memory should be leaked.

     
  • Daniel Aarno

    Daniel Aarno - 2007-02-17
    • status: open-wont-fix --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks