Skip to content

Commit

Permalink
SamplePlayHandle: Fix double-free, when the handle thinks it has an
Browse files Browse the repository at this point in the history
audioPort but it it is really someone else's.
  • Loading branch information
Reflexe authored and lukas-w committed Jul 30, 2018
1 parent cfa6253 commit 18a7f28
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/SamplePlayHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AudioPort;
class SamplePlayHandle : public PlayHandle
{
public:
SamplePlayHandle( SampleBuffer* sampleBuffer );
SamplePlayHandle(SampleBuffer* sampleBuffer , bool shouldCreateAudioPort=true);
SamplePlayHandle( const QString& sampleFile );
SamplePlayHandle( SampleTCO* tco );
virtual ~SamplePlayHandle();
Expand Down
13 changes: 7 additions & 6 deletions src/core/SamplePlayHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@



SamplePlayHandle::SamplePlayHandle( SampleBuffer* sampleBuffer ) :
SamplePlayHandle::SamplePlayHandle( SampleBuffer* sampleBuffer , bool shouldCreateAudioPort) :
PlayHandle( TypeSamplePlayHandle ),
m_sampleBuffer( sharedObject::ref( sampleBuffer ) ),
m_doneMayReturnTrue( true ),
m_frame( 0 ),
m_ownAudioPort( true ),
m_ownAudioPort( shouldCreateAudioPort ),
m_defaultVolumeModel( DefaultVolume, MinVolume, MaxVolume, 1 ),
m_volumeModel( &m_defaultVolumeModel ),
m_track( NULL ),
m_bbTrack( NULL )
{
setAudioPort( new AudioPort( "SamplePlayHandle", false ) );
if (shouldCreateAudioPort)
setAudioPort( new AudioPort( "SamplePlayHandle", false ) );
}




SamplePlayHandle::SamplePlayHandle( const QString& sampleFile ) :
SamplePlayHandle( new SampleBuffer( sampleFile ) )
SamplePlayHandle( new SampleBuffer( sampleFile ) , false)
{
sharedObject::unref( m_sampleBuffer );
setAudioPort( new AudioPort( "SamplePlayHandle", false ) );
Expand All @@ -60,7 +61,7 @@ SamplePlayHandle::SamplePlayHandle( const QString& sampleFile ) :


SamplePlayHandle::SamplePlayHandle( SampleTCO* tco ) :
SamplePlayHandle( tco->sampleBuffer() )
SamplePlayHandle( tco->sampleBuffer() , false)
{
m_track = tco->getTrack();
setAudioPort( ( (SampleTrack *)tco->getTrack() )->audioPort() );
Expand All @@ -72,7 +73,7 @@ SamplePlayHandle::SamplePlayHandle( SampleTCO* tco ) :
SamplePlayHandle::~SamplePlayHandle()
{
sharedObject::unref( m_sampleBuffer );
if( m_ownAudioPort )
if( m_ownAudioPort && audioPort ())
{
delete audioPort();
}
Expand Down

0 comments on commit 18a7f28

Please sign in to comment.