Skip to content

Commit abbe772

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 e2788c6 commit abbe772

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
@@ -226,7 +226,7 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
226226
ret = mfcc_get_window(state, config->window);
227227
if (ret < 0) {
228228
comp_err(dev, "Failed Window function");
229-
goto free_fft_out;
229+
goto free_fft_plan;
230230
}
231231

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

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

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

348348
/* Set initial state for STFT */
@@ -356,20 +356,26 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
356356
comp_dbg(dev, "done");
357357
return 0;
358358

359+
free_lifter:
360+
mod_free(mod, state->lifter.matrix);
361+
359362
free_dct_matrix:
360-
rfree(state->dct.matrix);
363+
mod_free(mod, state->dct.matrix);
361364

362365
free_melfb_data:
363-
rfree(fb->data);
366+
mod_free(mod, fb->data);
367+
368+
free_fft_plan:
369+
mod_fft_plan_free(mod, fft->fft_plan);
364370

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

368374
free_fft_buf:
369-
rfree(fft->fft_buf);
375+
mod_free(mod, fft->fft_buf);
370376

371377
free_buffers:
372-
rfree(state->buffers);
378+
mod_free(mod, state->buffers);
373379

374380
exit:
375381
return ret;

0 commit comments

Comments
 (0)