-
-
Notifications
You must be signed in to change notification settings - Fork 262
Fix for unsafe alloca
usage (CWE-770)
#412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3844,12 +3844,13 @@ bool AudioIoCallback::FillOutputBuffers( | |
|
||
// ------ MEMORY ALLOCATION ---------------------- | ||
// These are small structures. | ||
WaveTrack **chans = (WaveTrack **) alloca(numPlaybackChannels * sizeof(WaveTrack *)); | ||
float **tempBufs = (float **) alloca(numPlaybackChannels * sizeof(float *)); | ||
auto chans = new WaveTrack * [numPlaybackChannels]; | ||
auto tempBufs = new float* [numPlaybackChannels]; | ||
|
||
// And these are larger structures.... | ||
for (unsigned int c = 0; c < numPlaybackChannels; c++) | ||
tempBufs[c] = (float *) alloca(framesPerBuffer * sizeof(float)); | ||
for (unsigned int c = 0; c < numPlaybackChannels; c++) { | ||
tempBufs[c] = new float[framesPerBuffer]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memory leak. Tsk tsk. To compile with my other suggested change:
And then the missing But then other things are needed to fix the compilation too. Exercise for you. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See line 4006: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was incorrect, I missed a level on the essentially 3D array. |
||
} | ||
// ------ End of MEMORY ALLOCATION --------------- | ||
|
||
auto & em = RealtimeEffectManager::Get(); | ||
|
@@ -4001,6 +4002,8 @@ bool AudioIoCallback::FillOutputBuffers( | |
if (outputMeterFloats != outputFloats) | ||
ClampBuffer( outputMeterFloats, framesPerBuffer*numPlaybackChannels ); | ||
|
||
delete[] chans; | ||
delete[] tempBufs; | ||
return false; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly words of advice: no naked new! And (almost) never write delete (unless inside a destructor of your own smart pointer, or some cases where
delete this
is needed).I worked hard to banish them from Audacity. Don't let them creep back into your fork. Use proper RAII.