From 5c3834f8452c23c9e41ab1ba84c7ccd4fe0e90e8 Mon Sep 17 00:00:00 2001 From: Francisco Gil Date: Tue, 5 Dec 2017 09:29:35 +0100 Subject: [PATCH] adc: fix segmentation fault when exiting the application 'adc_sampling_cb_data' struct is a local variable of the 'main' function. Sometimes, the ADC callback accesses to it once the main function has exited (when it is out of scope), causing a segmentation fault. To solve this issue, adc_sampling_cb_data' struct is now a global variable. Signed-off-by: Francisco Gil --- apix-adc-example/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apix-adc-example/main.c b/apix-adc-example/main.c index 29b535d..3a55ec7 100644 --- a/apix-adc-example/main.c +++ b/apix-adc-example/main.c @@ -31,13 +31,14 @@ #define DEFAULT_TIME_INTERVAl 1 #define DEFAULT_NUMBER_OF_SAMPLES 10 -static adc_t *adc; - struct adc_sampling_cb_data { adc_t *adc; int number_of_samples; }; +static adc_t *adc; +struct adc_sampling_cb_data cb_data; + /* * usage_and_exit() - Show usage information and exit with 'exitval' return * value @@ -157,7 +158,6 @@ int main(int argc, char *argv[]) { int channel = 0, chip = 0, interval = 0, number_of_samples = 0; char *name = basename(argv[0]); - struct adc_sampling_cb_data cb_data; /* Check input parameters */ if (argc == 1) {