From 4ae77b69c9a8c24e5e8fa4fffdecb40a71f1531a Mon Sep 17 00:00:00 2001 From: xufulong Date: Tue, 28 Sep 2021 14:52:03 +0800 Subject: [PATCH] check out memory allocation --- app/src/main/cpp/visualizer/execute_fft.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/cpp/visualizer/execute_fft.cpp b/app/src/main/cpp/visualizer/execute_fft.cpp index 449eceb..be5b6cb 100644 --- a/app/src/main/cpp/visualizer/execute_fft.cpp +++ b/app/src/main/cpp/visualizer/execute_fft.cpp @@ -193,6 +193,7 @@ int init_visualizer(filter_sys_t *p_filter) p_filter->p_prev_s16_buff = nullptr; auto *w_param = (window_param*) malloc(sizeof(window_param)); + if (!w_param) return -1; p_filter->wind_param = *w_param; /* Fetch the FFT window parameters */ @@ -207,8 +208,12 @@ int init_visualizer(filter_sys_t *p_filter) p_filter->out_samples = FFT_BUFFER_SIZE; #endif p_filter->output = (int8_t *) (malloc(p_filter->out_samples * sizeof(int8_t))); + if (!p_filter->output) return -1; p_filter->data_size = MAX_FFT_SIZE; p_filter->data = (uint8_t *) (malloc(MAX_FFT_SIZE * sizeof(uint8_t))); + if (!p_filter->data) { + return -1; + } return 0; }