On Tuesday, November 16, 2010 10:59:38 am you wrote:
> On Tue, Nov 16, 2010 at 6:46 PM, Dave Steffen <dave.stef...@numerica.us> 
wrote:
> > Hi Folks
> > 
> > I've been tracking down some almost-certainly-false-positives.
> > Consider the following code:
> > 
> > 
> > #include <iostream>
> > #include <boost/shared_ptr.hpp>
> > #include <boost/make_shared.hpp>
> > 
> > 
> > using namespace std;
> > using boost::make_shared;
> > 
> > struct StateSpace {
> > public:
> > 
> >    StateSpace(int spaceType) {
> >        if (spaceType == 4)
> >            cout <<  "Some Output" << endl;
> >    }
> > };
> > 
> > class State {
> > public:
> > 
> > 
> >    State() : m_rep(make_shared<StateSpace>(0) ) {}   // #1
> > //    State() : m_rep(new StateSpace(0) ) {}          // #2
> > 
> > 
> >    boost::shared_ptr<StateSpace> m_rep;
> > };
> > 
> > 
> > int main() {
> >    State state;
> > }
> > 
> > 
> > Valgrind 3.6 reports this:
> > 
> > ==8198== Memcheck, a memory error detector
> > ==8198== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
> > ==8198== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
> > copyright info
> > ==8198== Command: testState
> > ==8198==
> > ==8198== Conditional jump or move depends on uninitialised value(s)
> > ==8198==    at 0x401659: StateSpace::StateSpace(int) (testState.cpp:14)
> > ==8198==    by 0x401796: boost::shared_ptr<StateSpace>
> > boost::make_shared<StateSpace, int, >(int&&, ) (make_shared.hpp:150)
> > ==8198==    by 0x4016BD: State::State() (testState.cpp:22)
> > ==8198==    by 0x401317: main (testState.cpp:29)
> > ==8198==
> > ==8198==
> > ==8198== HEAP SUMMARY:
> > ==8198==     in use at exit: 464 bytes in 5 blocks
> > ==8198==   total heap usage: 240 allocs, 236 frees, 45,162 bytes
> > allocated ==8198==
> > ==8198== LEAK SUMMARY:
> > ==8198==    definitely lost: 0 bytes in 0 blocks
> > ==8198==    indirectly lost: 0 bytes in 0 blocks
> > ==8198==      possibly lost: 0 bytes in 0 blocks
> > ==8198==    still reachable: 464 bytes in 5 blocks
> > ==8198==         suppressed: 0 bytes in 0 blocks
> > ==8198== Reachable blocks (those to which a pointer was found) are not
> > shown. ==8198== To see them, rerun with: --leak-check=full
> > --show-reachable=yes ==8198==
> > ==8198== For counts of detected and suppressed errors, rerun with: -v
> > ==8198== Use --track-origins=yes to see where uninitialised values come
> > from ==8198== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 5
> > from 5)
> > 
> > 
> > Interestingly, commenting out line 1 and replacing it with line 2
> > produces no errors.
> 
> Can you rerun it with: --track-origins=yes ?
> 
> Regards
> Gateano Mendola

Yes indeed:

==8416== Memcheck, a memory error detector
==8416== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==8416== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for 
copyright info
==8416== Command: testState
==8416== 
==8416== Conditional jump or move depends on uninitialised value(s)
==8416==    at 0x401659: StateSpace::StateSpace(int) (testState.cpp:14)
==8416==    by 0x401796: boost::shared_ptr<StateSpace> 
boost::make_shared<StateSpace, int, >(int&&, ) (make_shared.hpp:150)
==8416==    by 0x4016BD: State::State() (testState.cpp:22)
==8416==    by 0x401317: main (testState.cpp:30)
==8416==  Uninitialised value was created by a stack allocation
==8416==    at 0x40176A: boost::shared_ptr<StateSpace> 
boost::make_shared<StateSpace, int, >(int&&, ) (make_shared.hpp:150)
==8416== 
==8416== 
==8416== HEAP SUMMARY:
==8416==     in use at exit: 464 bytes in 5 blocks
==8416==   total heap usage: 238 allocs, 234 frees, 28,778 bytes allocated
==8416== 
==8416== LEAK SUMMARY:
==8416==    definitely lost: 0 bytes in 0 blocks
==8416==    indirectly lost: 0 bytes in 0 blocks
==8416==      possibly lost: 0 bytes in 0 blocks
==8416==    still reachable: 464 bytes in 5 blocks
==8416==         suppressed: 0 bytes in 0 blocks
==8416== Reachable blocks (those to which a pointer was found) are not shown.
==8416== To see them, rerun with: --leak-check=full --show-reachable=yes
==8416== 
==8416== For counts of detected and suppressed errors, rerun with: -v
==8416== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 5 from 5)


FWIW, here's the relevent chunk of make_shared.hpp:

template< class T, class Arg1, class... Args > boost::shared_ptr< T > 
make_shared( Arg1 && arg1, Args && ... args )
{
    boost::shared_ptr< T > pt( static_cast< T* >( 0 ), 
boost::detail::sp_ms_deleter< T >() );

    boost::detail::sp_ms_deleter< T > * pd = boost::get_deleter< 
boost::detail::sp_ms_deleter< T > >( pt );

    void * pv = pd->address();

    ::new( pv ) T( boost::detail::sp_forward<Arg1>( arg1 ), 
boost::detail::sp_forward<Args>( args )... );
    pd->set_initialized();

    T * pt2 = static_cast< T* >( pv );

    boost::detail::sp_enable_shared_from_this( &pt, pt2, pt2 );
    return boost::shared_ptr< T >( pt, pt2 );
}

Line 150 is the one with the call to ::new

-- 
Dave Steffen, Ph.D. - Software Engineer

Numerica Corporation <http://www.numerica.us>
4850 Hahns Peak Drive, Suite 200
Loveland, Colorado 80538
main (970) 461-2000 x 227   direct (970) 612-2327
Email: dave.stef...@numerica.us
fax (970) 461-2004

This message and any attachments are intended only for the individual
or entity to which the message is addressed.  This is a private
message and may contain privileged information.  If you are neither
the intended recipient nor the agent responsible for delivering the
message to the intended recipient, you are hereby notified that any
review, retransmission, dissemination, or taking of any action in
reliance upon, the information in this communication is strictly
prohibited, and may be unlawful.  If you feel you have received this
communication in error, please notify me immediately by returning this
email to me and deleting it from your computer.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to