|
From: Edward M. <edw...@ce...> - 2004-06-22 14:38:45
|
Hi all,
I'm completely stumped by an error reported by valgrind, and I was wonderin=
g=20
if any of you had a better idea than me about what it means.
The error is:
=3D=3D25213=3D=3D Invalid write of size 4
=3D=3D25213=3D=3D =A0 =A0at 0x5B839E56: Trk::Track::Track(Trk::Track::Track=
Author,=20
DataVector<Trk::TrackParameters const>*, DataVector<Trk::RIO_OnTrack const>=
*,=20
Trk::FitQuality const*) (../src/Track.cxx:59)
=3D=3D25213=3D=3D =A0 =A0by 0x66AEC9E6: Trk::IPatToTrackTool::convert(Track=
const&)=20
(../src/IPatToTrackTool.cxx:107)
=3D=3D25213=3D=3D =A0 =A0by 0x66AFCC7C: Trk::LegacyCnvAlg::convertIPat()=20
(../src/LegacyCnvAlg.cxx:98)
=3D=3D25213=3D=3D =A0 =A0by 0x66AFC949: Trk::LegacyCnvAlg::execute()=20
(../src/LegacyCnvAlg.cxx:73)
=3D=3D25213=3D=3D =A0 =A0Address 0x6E145140 is 0 bytes after a block of siz=
e 28 alloc'd
=3D=3D25213=3D=3D =A0 =A0at 0x4002A929: __builtin_new (vg_replace_malloc.c:=
172)
=3D=3D25213=3D=3D =A0 =A0by 0x4002A994: operator new(unsigned) (vg_replace_=
malloc.c:185)
=3D=3D25213=3D=3D =A0 =A0by 0x66AEC9C6: Trk::IPatToTrackTool::convert(Track=
const&)=20
(../src/IPatToTrackTool.cxx:107)
=3D=3D25213=3D=3D =A0 =A0by 0x66AFCC7C: Trk::LegacyCnvAlg::convertIPat()=20
(../src/LegacyCnvAlg.cxx:98)
So, I think that this means that the Track constructor is trying to write 4=
=20
bytes to 0x6E145140 , which does not belong to the Track.
The relevant lines of Track are:
Trk::Track::Track (
=A0=A0=A0=A0=A0=A0=A0=A0TrackAuthor author,=20
=A0=A0=A0=A0=A0=A0=A0=A0DataVector<const Trk::TrackParameters>* parameters,=
=20
=A0=A0=A0=A0=A0=A0=A0=A0DataVector<const Trk::RIO_OnTrack>* hits,
=A0=A0=A0=A0=A0=A0=A0=A0const Trk::FitQuality* fitQuality
=A0=A0=A0=A0=A0=A0=A0=A0):
=A0=A0=A0=A0=A0=A0=A0=A0m_mode(FullMode),
=A0=A0=A0=A0=A0=A0=A0=A0m_parameterVector(parameters),
=A0=A0=A0=A0=A0=A0=A0=A0m_extraParameterVector(0),
=A0=A0=A0=A0=A0=A0=A0=A0m_rioVector(hits), =A0 =A0
=A0=A0=A0=A0=A0=A0=A0=A0m_trackStateVector( 0 ),
=A0=A0=A0=A0=A0=A0=A0=A0m_perigeeParameters( 0 ),
=A0=A0=A0=A0=A0=A0=A0=A0m_fitQuality(fitQuality),
=A0=A0=A0=A0=A0=A0=A0=A0m_author(author)
{ <- error reported on this line.
Now since all of the variables being initialised are either pointers or enu=
ms=20
(m_mode and m_author) I just don't understand how there can be a write to=20
unallocated memory. Surely they are all created when Track is created?
What is incredibly weird (to me at least) is that the following produces no=
=20
error:
Trk::Track::Track (
TrackAuthor author,=20
DataVector<const Trk::TrackParameters>* parameters,=20
DataVector<const Trk::RIO_OnTrack>* hits,
const Trk::FitQuality* fitQuality
)
{
m_mode=3D FullMode;
m_parameterVector=3D parameters;
m_extraParameterVector=3D0;
m_rioVector=3Dhits;=20
m_trackStateVector=3D 0 ;
m_perigeeParameters=3D 0 ;
m_fitQuality =3D fitQuality;
m_author =3D author;
Is it not almost identical?
Why is it an error in the initialisation list, but not if I "manually"=20
initialise the parameters?
I'm *SURE* there is a serious problem because I get nasty crashes later on=
=20
which look like memory violations. However valgrind seems not to pick=20
anything up apart from the above.
Thanks for any help anyone can give - I'm at my wits end with this!
valgrind --version
valgrind-20031012
Cheers,
Ed
|
|
From: Andrew C. <and...@ya...> - 2004-06-22 15:06:59
|
On Tuesday 22 Jun 2004 15:38, Edward Moyse wrote: > Hi all, > > I'm completely stumped by an error reported by valgrind, and I was > wondering if any of you had a better idea than me about what it means. > > What is incredibly weird (to me at least) is that the following produces no > error: > <snip> > Is it not almost identical? (For future reference - see footnote 1) > Why is it an error in the initialisation list, but not if I "manually" > initialise the parameters? > Try pulling parameters one at a time from being initialised in the constructor to being initialised by the initialisation syntax - that way you can at least isolate what variable is causing the problem. The problem with the initialisation syntax is that it doesn't say which of the initialisations caused the error... Andrew [1] The difference is that if you use the initialisation syntax it uses the copy constructors to create the objects, with the constructor parameters specified; if you assign to them in the constructor later it default-constructs the objects where the initialisation was done previously and then uses the assignment operator. If you have const members and want them to have any value assigned to them, you have to use the initialisation syntax. In your case, however, you're just using pointers and enums so they're not initialised at all and then just assigned over... |