Memory leak

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory leak

Gie-2
When exception is throw in sample below,  VisualStudio (VC7.1) reports memory leak, any hints?

    struct CNumericValidator: public s::grammar<CNumericValidator>
    {
        template <typename ScannerT>
        struct definition
        {
            s::rule<ScannerT>  r;
            definition(CNumericValidator const& self)  
            {

                if( self.min_ == self.max_ )
                {
                    if(  self.min_==0 )
                        r = *s::digit_p >> s::end_p;
                    else
                        r = s::repeat_p (self.min_) [s::digit_p] >> s::end_p;
                }
                else
                    if( self.min_ > self.max_ )
                    {
                        if( self.max_!=0 ) throw std::runtime_error("min_>max");
                        else
                            r = s::repeat_p (self.min_, s::more) [s::digit_p] >> s::end_p;

                    }
                    else // if( self.min_ < self.max_ )
                        r = s::repeat_p (self.min_, self.max_) [s::digit_p] >> s::end_p;

            }

            s::rule<ScannerT> const& start() const { return r; }
        };

        CNumericValidator(const unsigned int minRep, const unsigned int maxRep)
            : min_( minRep )
            , max_( maxRep )
        {}

        const unsigned int min_;
        const unsigned int max_;
    };


Block to be leaking is seamed to be allocated by
            if (definitions.size()<=id)
                definitions.resize(id*3/2+1);
lines (grammar.ipp @ 170, boost_1_33_0).



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: Memory leak

Carl Barron

On Sep 26, 2005, at 6:31 AM, GIE wrote:

>      if( self.max_!=0 ) throw std::runtime_error("min_>max");

change this to
        if (self_max_!=0) r = eps_p[throw_invalid()]; // eps always matches a
zero length string.


and use this action

  struct throw_invalid
{
        template <class I>
        void operator () (I,I) const {throw std::runtime_error("min >
max");}
};

this move the exception out of the constructor and will throw the
exception as soon as
your parser attempts to parse anything,

Throwing exceptions in constructors that can be avoided should be
avoided, Particularly
in classes you don't write entirely. Such as grammars,,,



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general