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


-- 
cpp-today.blogspot.com

------------------------------------------------------------------------------
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