mirror of
https://github.com/cuberite/TCLAP.git
synced 2025-09-18 16:46:18 -04:00
fixed output memory leak
This commit is contained in:
parent
8497556541
commit
3c4771b03c
@ -591,7 +591,10 @@ int main(int argc, char** argv)
|
||||
</pre><p>
|
||||
|
||||
See <tt class="filename">test4.cpp</tt> in the examples directory for the full
|
||||
example.
|
||||
example. <span class="emphasis"><em>NOTE</em></span>: if you supply your own Output object, we
|
||||
will not delete it in the <tt class="classname">CmdLine</tt> destructor. This
|
||||
could lead to a (very small) memory leak if you don't take care of the object
|
||||
yourself.
|
||||
</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="EXCEPTIONS"></a>Chapter 3. Exceptions to the Rules</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#IGNORE_ARGS">Ignoring arguments</a></dt><dt><a href="#COMBINED_SWITCHES">Multiple Identical Switches</a></dt><dt><a href="#DESCRIPTION_EXCEPTIONS">Type Descriptions</a></dt></dl></div><p>
|
||||
Like all good rules, there are many exceptions....
|
||||
</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="IGNORE_ARGS"></a>Ignoring arguments</h2></div></div><div></div></div><p>
|
||||
|
@ -750,7 +750,10 @@ int main(int argc, char** argv)
|
||||
</programlisting>
|
||||
|
||||
See <filename>test4.cpp</filename> in the examples directory for the full
|
||||
example.
|
||||
example. <emphasis>NOTE</emphasis>: if you supply your own Output object, we
|
||||
will not delete it in the <classname>CmdLine</classname> destructor. This
|
||||
could lead to a (very small) memory leak if you don't take care of the object
|
||||
yourself.
|
||||
</para>
|
||||
</sect1>
|
||||
</chapter>
|
||||
|
@ -136,6 +136,12 @@ class CmdLine : public CmdLineInterface
|
||||
*/
|
||||
void deleteOnExit(Visitor* ptr);
|
||||
|
||||
/**
|
||||
* Is set to true when a user sets the output object. We use this so
|
||||
* that we don't delete objects that are created outside of this lib.
|
||||
*/
|
||||
bool _userSetOutput;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@ -258,7 +264,8 @@ inline CmdLine::CmdLine(const std::string& n,
|
||||
_message(m),
|
||||
_version(v),
|
||||
_numRequired(0),
|
||||
_delimiter(' ')
|
||||
_delimiter(' '),
|
||||
_userSetOutput(false)
|
||||
{
|
||||
_constructor();
|
||||
}
|
||||
@ -270,7 +277,8 @@ inline CmdLine::CmdLine(const std::string& m,
|
||||
_message(m),
|
||||
_version(v),
|
||||
_numRequired(0),
|
||||
_delimiter(delim)
|
||||
_delimiter(delim),
|
||||
_userSetOutput(false)
|
||||
{
|
||||
_constructor();
|
||||
}
|
||||
@ -289,6 +297,9 @@ inline CmdLine::~CmdLine()
|
||||
visIter != _visitorDeleteOnExitList.end();
|
||||
++visIter)
|
||||
delete *visIter;
|
||||
|
||||
if ( !_userSetOutput )
|
||||
delete _output;
|
||||
}
|
||||
|
||||
inline void CmdLine::_constructor()
|
||||
@ -439,6 +450,7 @@ inline CmdLineOutput* CmdLine::getOutput()
|
||||
|
||||
inline void CmdLine::setOutput(CmdLineOutput* co)
|
||||
{
|
||||
_userSetOutput = true;
|
||||
_output = co;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user