From a826daec5df675db32b2f2c98c8e19569d871210 Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Sat, 18 Mar 2023 21:18:23 +0100 Subject: [PATCH] minor: Change rtlsdr_find_tuner_gain to stack memory --- src/sdr.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sdr.c b/src/sdr.c index 1a00ba986..94fc7c862 100644 --- a/src/sdr.c +++ b/src/sdr.c @@ -455,11 +455,13 @@ static int rtlsdr_find_tuner_gain(sdr_dev_t *dev, int centigain, int verbose) print_log(LOG_WARNING, __func__, "No exact gains"); return centigain; } - int *gains = calloc(gains_count, sizeof(int)); - if (!gains) { - WARN_CALLOC("rtlsdr_find_tuner_gain()"); - return centigain; // NOTE: just aborts on alloc failure. + if (gains_count > 29) { + print_log(LOG_ERROR, __func__, "Unexpected gain count, notify maintainers please!"); + return centigain; } + // We known the maximum nunmber of gains is 29. + // Let's not waste an alloc + int gains[29] = {0}; rtlsdr_get_tuner_gains(dev->rtlsdr_dev, gains); /* Find allowed gain */ @@ -472,7 +474,6 @@ static int rtlsdr_find_tuner_gain(sdr_dev_t *dev, int centigain, int verbose) if (centigain > gains[gains_count - 1]) { centigain = gains[gains_count - 1]; } - free(gains); return centigain; }