Skip to content
Snippets Groups Projects
Commit 597c256d authored by deuce's avatar deuce
Browse files

Fix memory leak found by scan-build.

parent c75a81cd
Branches
Tags
No related merge requests found
......@@ -826,6 +826,10 @@ error_return:
sample_thread_running=FALSE;
}
/*
* This MUST not return false after sample goes into the sample buffer in the background.
* If it does, the caller won't be able to free() it.
*/
BOOL DLLCALL xp_play_sample(const unsigned char *sample, size_t size, BOOL background)
{
if(!sample_initialized) {
......@@ -985,6 +989,7 @@ BOOL DLLCALL xptone(double freq, DWORD duration, enum WAVE_SHAPE shape)
{
unsigned char *wave;
int samples;
BOOL ret;
wave=(unsigned char *)malloc(S_RATE*15/2+1);
if(!wave)
......@@ -1004,13 +1009,17 @@ BOOL DLLCALL xptone(double freq, DWORD duration, enum WAVE_SHAPE shape)
;
sample_len++;
while(samples > S_RATE*15/2) {
if(!xp_play_sample(wave, sample_len, TRUE))
if(!xp_play_sample(wave, sample_len, TRUE)) {
free(wave);
return FALSE;
}
samples -= sample_len;
}
}
makewave(freq,wave,samples,shape);
return(xp_play_sample(wave, samples, FALSE));
ret = xp_play_sample(wave, samples, FALSE);
free(wave);
return ret;
}
#ifdef __unix__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment