Skip to content

Commit 3fa6de7

Browse files
committed
Audio: MFCC: Fix error handling in mfcc_setup
Add missing cleanup for fft_plan. After mod_fft_plan_new() succeeds, failures in window setup and mel filterbank initialization jumped to free_fft_out, leaking the fft_plan. Add free_fft_plan label and route these error paths through it. Add missing cleanup for lifter.matrix. Late validation checks (mel_log_32 space, output capacity) jumped to free_dct_matrix, skipping the lifter matrix that may have been allocated. Add free_lifter label for these paths. Replace rfree() with mod_free() in all error cleanup labels to match the mod_zalloc() allocations and the existing mfcc_free_buffers() implementation. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent d2cf265 commit 3fa6de7

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/audio/mfcc/mfcc_setup.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
222222
ret = mfcc_get_window(state, config->window);
223223
if (ret < 0) {
224224
comp_err(dev, "Failed Window function");
225-
goto free_fft_out;
225+
goto free_fft_plan;
226226
}
227227

228228
/* Setup Mel auditory filterbank. FFT input and output buffers are used
@@ -244,7 +244,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
244244
ret = mod_psy_get_mel_filterbank(mod, fb);
245245
if (ret < 0) {
246246
comp_err(dev, "Failed Mel filterbank");
247-
goto free_fft_out;
247+
goto free_fft_plan;
248248
}
249249

250250
/* Setup DCT and cepstral lifter only when num_ceps > 0.
@@ -310,7 +310,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
310310
comp_err(dev, "num_mel_bins %d exceeds mel_log_32 scratch space %d",
311311
config->num_mel_bins, mel_log_32_space);
312312
ret = -EINVAL;
313-
goto free_dct_matrix;
313+
goto free_lifter;
314314
}
315315

316316
state->mel_spectra = (struct mat_matrix_16b *)&fft->fft_out[0];
@@ -339,7 +339,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
339339
comp_err(dev, "Output %d int16 per hop exceeds sink capacity %d (hop %d x ch %d)",
340340
out_per_hop, sink_per_hop, fft->fft_hop_size, channels);
341341
ret = -EINVAL;
342-
goto free_dct_matrix;
342+
goto free_lifter;
343343
}
344344

345345
/* Set initial state for STFT */
@@ -353,20 +353,26 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
353353
comp_dbg(dev, "done");
354354
return 0;
355355

356+
free_lifter:
357+
mod_free(mod, state->lifter.matrix);
358+
356359
free_dct_matrix:
357-
rfree(state->dct.matrix);
360+
mod_free(mod, state->dct.matrix);
358361

359362
free_melfb_data:
360-
rfree(fb->data);
363+
mod_free(mod, fb->data);
364+
365+
free_fft_plan:
366+
mod_fft_plan_free(mod, fft->fft_plan);
361367

362368
free_fft_out:
363-
rfree(fft->fft_out);
369+
mod_free(mod, fft->fft_out);
364370

365371
free_fft_buf:
366-
rfree(fft->fft_buf);
372+
mod_free(mod, fft->fft_buf);
367373

368374
free_buffers:
369-
rfree(state->buffers);
375+
mod_free(mod, state->buffers);
370376

371377
exit:
372378
return ret;

0 commit comments

Comments
 (0)