|
Boost Users : |
Subject: [Boost-users] Valgrind false positive in make_shared
From: Dave Steffen (dave.steffen_at_[hidden])
Date: 2010-11-16 12:16:52
Hi Folks
I've been tracking down some almost-certainly-false-positives from
Valgrind. 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) ) {}
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, if I change
State() : m_rep(make_shared<StateSpace>(0) ) {}
to
State() : m_rep(new StateSpace(0)) {}
the Valgrind error goes away.
This is, of course, a greatly boiled-down version of our actual code,
which we're very confident works correctly. Any ideas about why
Valgrind doesn't like the call to make_shared? Any ideas about how to
silence this warning (other than adding it to Valgrind's suppressions
file)?
Thanks very much.
-- 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.steffen_at_[hidden] fax (970) 461-2004
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net