From e2678830bab0472cb92ec280d89fbfbdc665b89f Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 19 Oct 2009 14:10:31 +0000 Subject: [PATCH] Use auto_ptr when calling SGSoundSample --- src/ATCDCL/ATC.cxx | 4 +++- src/Sound/beacon.cxx | 12 ++++++------ src/Sound/morse.cxx | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ATCDCL/ATC.cxx b/src/ATCDCL/ATC.cxx index 92568edc5..480257bc7 100644 --- a/src/ATCDCL/ATC.cxx +++ b/src/ATCDCL/ATC.cxx @@ -237,8 +237,10 @@ void FGATC::Render(string& msg, const float volume, // >>> Beware: must pass a (new) object to the (add) method, // >>> because the (remove) method is going to do a (delete) // >>> whether that's what you want or not. + std::auto_ptr ptr; + ptr.reset((unsigned char*) buf.c_str()); SGSoundSample *simple = - new SGSoundSample((unsigned char*) buf.c_str(), buf.length(), 8000); + new SGSoundSample(ptr, buf.length(), 8000); // TODO - at the moment the volume can't be changed // after the transmission has started. simple->set_volume(volume); diff --git a/src/Sound/beacon.cxx b/src/Sound/beacon.cxx index 9b5f353af..6de5f4624 100644 --- a/src/Sound/beacon.cxx +++ b/src/Sound/beacon.cxx @@ -41,9 +41,9 @@ bool FGBeacon::init() { int len; unsigned char *ptr; - unsigned char *inner_buf = new unsigned char[ INNER_SIZE ] ; - unsigned char *middle_buf = new unsigned char[ MIDDLE_SIZE ] ; - unsigned char *outer_buf = new unsigned char[ OUTER_SIZE ] ; + std::auto_ptrinner_buf( new unsigned char[ INNER_SIZE ] ); + std::auto_ptrmiddle_buf( new unsigned char[ MIDDLE_SIZE ] ); + std::auto_ptrouter_buf( new unsigned char[ OUTER_SIZE ] ); // Make inner marker beacon sound len= (int)(INNER_DIT_LEN / 2.0 ); @@ -51,7 +51,7 @@ bool FGBeacon::init() { make_tone( inner_dit, INNER_FREQ, len, INNER_DIT_LEN, TRANSITION_BYTES ); - ptr = inner_buf; + ptr = inner_buf.get(); for ( i = 0; i < 6; ++i ) { memcpy( ptr, inner_dit, INNER_DIT_LEN ); ptr += INNER_DIT_LEN; @@ -73,7 +73,7 @@ bool FGBeacon::init() { make_tone( middle_dah, MIDDLE_FREQ, len, MIDDLE_DAH_LEN, TRANSITION_BYTES ); - ptr = middle_buf; + ptr = middle_buf.get(); memcpy( ptr, middle_dit, MIDDLE_DIT_LEN ); ptr += MIDDLE_DIT_LEN; memcpy( ptr, middle_dah, MIDDLE_DAH_LEN ); @@ -88,7 +88,7 @@ bool FGBeacon::init() { make_tone( outer_dah, OUTER_FREQ, len, OUTER_DAH_LEN, TRANSITION_BYTES ); - ptr = outer_buf; + ptr = outer_buf.get(); memcpy( ptr, outer_dah, OUTER_DAH_LEN ); ptr += OUTER_DAH_LEN; memcpy( ptr, outer_dah, OUTER_DAH_LEN ); diff --git a/src/Sound/morse.cxx b/src/Sound/morse.cxx index a56273288..c9195e78d 100644 --- a/src/Sound/morse.cxx +++ b/src/Sound/morse.cxx @@ -219,10 +219,10 @@ SGSoundSample *FGMorse::make_ident( const string& id, const int freq ) { length += 2 * SPACE_SIZE; // 2. Allocate space for the message - unsigned char *buffer = new unsigned char[length]; + std::auto_ptrbuffer( new unsigned char[length] ); // 3. Assemble the message; - unsigned char *buf_ptr = buffer; + unsigned char *buf_ptr = buffer.get(); for ( i = 0; i < (int)id.length(); ++i ) { if ( idptr[i] >= 'A' && idptr[i] <= 'Z' ) { -- 2.39.5