From 9aa52f3e18c261eb6a119a3776f4ce51c7291aef Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Tue, 6 May 2008 21:32:37 -0500 Subject: [PATCH] Fix memory leaks reported by valgrind. --- Timeline/Annotation_Point.H | 12 ------------ Timeline/Audio_Sequence.C | 4 +++- Timeline/Control_Sequence.C | 2 +- Timeline/Loggable.C | 3 +++ Timeline/Sequence.C | 3 ++- Timeline/Sequence_Point.H | 11 +++++++++++ Timeline/Tempo_Point.C | 1 - Timeline/Tempo_Point.H | 2 +- Timeline/Time_Point.H | 3 +-- Timeline/Track.C | 4 ++++ 10 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Timeline/Annotation_Point.H b/Timeline/Annotation_Point.H index 373501c..ce38813 100644 --- a/Timeline/Annotation_Point.H +++ b/Timeline/Annotation_Point.H @@ -27,17 +27,6 @@ class Annotation_Point : public Sequence_Point { -public: - - const char *name ( void ) const { return _label; } - void name ( const char *s ) - { - if ( _label ) - free( _label ); - _label = strdup( s ); - redraw(); - } - protected: // const char *class_name ( void ) { return "Annotation_Point"; } @@ -101,7 +90,6 @@ public: ~Annotation_Point ( ) { log_destroy(); - if ( _label ) free( _label ); } diff --git a/Timeline/Audio_Sequence.C b/Timeline/Audio_Sequence.C index a45917b..5041a92 100644 --- a/Timeline/Audio_Sequence.C +++ b/Timeline/Audio_Sequence.C @@ -81,7 +81,7 @@ Audio_Sequence::set ( Log_Entry &e ) t->track( this ); } else if ( ! strcmp( ":n", s ) ) - name( strdup( v ) ); + name( v ); } } @@ -238,6 +238,8 @@ Audio_Sequence::handle ( int m ) return 0; } + free( file ); + // Audio_Region *r = new Audio_Region( c, this, timeline->xoffset + timeline->x_to_ts( Fl::event_x() - x() ) ); diff --git a/Timeline/Control_Sequence.C b/Timeline/Control_Sequence.C index f7069fa..4e274cc 100644 --- a/Timeline/Control_Sequence.C +++ b/Timeline/Control_Sequence.C @@ -86,7 +86,7 @@ Control_Sequence::set ( Log_Entry &e ) t->add( this ); } else if ( ! strcmp( ":n", s ) ) - name( strdup( v ) ); + name( v ); } } diff --git a/Timeline/Loggable.C b/Timeline/Loggable.C index c9e3bfd..d0cc433 100644 --- a/Timeline/Loggable.C +++ b/Timeline/Loggable.C @@ -348,6 +348,9 @@ Loggable::do_this ( const char *s, bool reverse ) } + if ( arguments ) + free( arguments ); + return true; } diff --git a/Timeline/Sequence.C b/Timeline/Sequence.C index a33fbb7..b492132 100644 --- a/Timeline/Sequence.C +++ b/Timeline/Sequence.C @@ -58,7 +58,8 @@ Sequence::init ( void ) Sequence::~Sequence ( ) { - /* FIXME: what to do with regions? */ + if ( _name ) + free( _name ); for ( std::list ::iterator i = _widgets.begin(); i != _widgets.end(); ++i ) diff --git a/Timeline/Sequence_Point.H b/Timeline/Sequence_Point.H index 9cead90..777635c 100644 --- a/Timeline/Sequence_Point.H +++ b/Timeline/Sequence_Point.H @@ -33,6 +33,15 @@ protected: public: + const char *name ( void ) const { return _label; } + void name ( const char *s ) + { + if ( _label ) + free( _label ); + _label = strdup( s ); + redraw(); + } + Fl_Align align ( void ) const { return FL_ALIGN_RIGHT; } virtual int abs_w ( void ) const { return 8; } @@ -63,6 +72,8 @@ public: virtual ~Sequence_Point ( ) { + if ( _label ) + free( _label ); } virtual void draw_box ( void ); diff --git a/Timeline/Tempo_Point.C b/Timeline/Tempo_Point.C index 23cf239..62d6d15 100644 --- a/Timeline/Tempo_Point.C +++ b/Timeline/Tempo_Point.C @@ -67,7 +67,6 @@ Tempo_Point::Tempo_Point ( nframes_t when, float bpm ) Tempo_Point::~Tempo_Point ( ) { - if ( _label ) delete[] _label; log_destroy(); } diff --git a/Timeline/Tempo_Point.H b/Timeline/Tempo_Point.H index 4b4246b..f5350c6 100644 --- a/Timeline/Tempo_Point.H +++ b/Timeline/Tempo_Point.H @@ -30,7 +30,7 @@ class Tempo_Point : public Sequence_Point _make_label ( void ) { if ( ! _label ) - _label = new char[40]; + _label = (char*)malloc( 40 ); snprintf( _label, 40, "%.1f", _tempo ); } diff --git a/Timeline/Time_Point.H b/Timeline/Time_Point.H index 653071a..c76b113 100644 --- a/Timeline/Time_Point.H +++ b/Timeline/Time_Point.H @@ -51,7 +51,7 @@ class Time_Point : public Sequence_Point _make_label ( void ) { if ( ! _label ) - _label = new char[40]; + _label = (char*)malloc( 40 ); snprintf( _label, 40, "%d/%d", _time.beats_per_bar, _time.beat_type ); } @@ -94,7 +94,6 @@ public: ~Time_Point ( ) { - if ( _label ) delete[] _label; log_destroy(); } diff --git a/Timeline/Track.C b/Timeline/Track.C index 1f05e67..69b1bc5 100644 --- a/Timeline/Track.C +++ b/Timeline/Track.C @@ -259,10 +259,14 @@ Track::~Track ( ) for ( int i = control_out.size(); i--; ) { control_out.back()->shutdown(); + delete control_out.back(); control_out.pop_back(); } log_destroy(); + + if ( _name ) + free( _name ); }