[Insight-developers] itkVariableLengthVector
Karthik Krishnan
Karthik.Krishnan at kitware.com
Tue Aug 15 11:45:38 EDT 2006
Thanks.. Yes. That would have resulted in an free of nonexistant data if
SetSize was called twice.
Brad Davis wrote:
> I seem to have found a memory bug in VariableLengthVector.
>
> The SetSize method needs to add the line commented below. Otherwise,
> m_Data is incorrectly accessed when the Reserve method is called. I
> have tested the change with the current cvs version of Insight and all
> tests pass (Linux-x86_64, gcc 4.0.4).
>
> template < typename TValueType >
> void VariableLengthVector<TValueType >
> ::SetSize(unsigned int sz, bool destroyExistingData)
> {
> if( destroyExistingData )
> {
> // Free any existing data if we manage its memory and if we need to
> destroy
> if(!m_LetArrayManageMemory)
> {
> m_Data=0;
> m_NumElements = 0;
> }
> else if( m_Data )
> {
> if( (m_NumElements != sz))
> {
> if(m_NumElements>0)
> {
> delete [] m_Data;
> m_Data = 0; // THIS LINE MUST BE ADDED
> }
> }
> else return;
> }
> }
>
> if ( m_NumElements != sz )
> {
> Reserve( sz );
> }
> }
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
>
More information about the Insight-developers
mailing list