Added special strdup to liboptions, to prevent memory leaks for option strings
If you are doing memory leak debugging you don't want to see any leaks when stopping the program.
This commit is contained in:
parent
d65cb69145
commit
47185e80b7
|
@ -28,6 +28,7 @@
|
|||
#include "../libsample/sample.h"
|
||||
#include "debug.h"
|
||||
#include "../libdisplay/display.h"
|
||||
#include "../liboptions/options.h"
|
||||
|
||||
const char *debug_level[] = {
|
||||
"debug ",
|
||||
|
@ -206,7 +207,7 @@ int parse_debug_opt(const char *optarg)
|
|||
for (i = 0; debug_level[i]; i++)
|
||||
max_level = i;
|
||||
|
||||
dstring = strdup(optarg);
|
||||
dstring = options_strdup(optarg);
|
||||
p = strsep(&dstring, ",");
|
||||
for (i = 0; i < p[i]; i++) {
|
||||
if (p[i] < '0' || p[i] > '9') {
|
||||
|
|
|
@ -83,7 +83,7 @@ const char *console_digits = "0123456789";
|
|||
|
||||
void main_mobile_init(void)
|
||||
{
|
||||
cc_argv[cc_argc++] = strdup("remote auto");
|
||||
cc_argv[cc_argc++] = options_strdup("remote auto");
|
||||
|
||||
got_init = 1;
|
||||
#ifdef HAVE_SDR
|
||||
|
@ -265,7 +265,7 @@ int main_mobile_handle_options(int short_option, int argi, char **argv)
|
|||
OPT_ARRAY(num_kanal, kanal, argv[argi])
|
||||
break;
|
||||
case 'a':
|
||||
OPT_ARRAY(num_audiodev, audiodev, strdup(argv[argi]))
|
||||
OPT_ARRAY(num_audiodev, audiodev, options_strdup(argv[argi]))
|
||||
break;
|
||||
case 's':
|
||||
samplerate = atoi(argv[argi]);
|
||||
|
@ -319,10 +319,10 @@ int main_mobile_handle_options(int short_option, int argi, char **argv)
|
|||
fprintf(stderr, "Too many osmo-cc args!\n");
|
||||
break;
|
||||
}
|
||||
cc_argv[cc_argc++] = strdup(argv[argi]);
|
||||
cc_argv[cc_argc++] = options_strdup(argv[argi]);
|
||||
break;
|
||||
case 'c':
|
||||
call_audiodev = strdup(argv[argi]);
|
||||
call_audiodev = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_CALL_SAMPLERATE:
|
||||
call_samplerate = atoi(argv[argi]);
|
||||
|
@ -340,16 +340,16 @@ int main_mobile_handle_options(int short_option, int argi, char **argv)
|
|||
fast_math = 1;
|
||||
break;
|
||||
case OPT_WRITE_RX_WAVE:
|
||||
write_rx_wave = strdup(argv[argi]);
|
||||
write_rx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_WRITE_TX_WAVE:
|
||||
write_tx_wave = strdup(argv[argi]);
|
||||
write_tx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_READ_RX_WAVE:
|
||||
read_rx_wave = strdup(argv[argi]);
|
||||
read_rx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_READ_TX_WAVE:
|
||||
read_tx_wave = strdup(argv[argi]);
|
||||
read_tx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
#ifdef HAVE_SDR
|
||||
case OPT_LIMESDR:
|
||||
|
|
|
@ -36,6 +36,27 @@ static option_t *option_head = NULL;
|
|||
static option_t **option_tailp = &option_head;
|
||||
static int first_option = 1;
|
||||
|
||||
static struct options_strdup_entry {
|
||||
struct options_strdup_entry *next;
|
||||
char s[1];
|
||||
} *options_strdup_list = NULL;
|
||||
|
||||
char *options_strdup(const char *s)
|
||||
{
|
||||
struct options_strdup_entry *o;
|
||||
|
||||
o = malloc(sizeof(struct options_strdup_entry) + strlen(s));
|
||||
if (!o) {
|
||||
PDEBUG(DOPTIONS, DEBUG_ERROR, "No mem!\n");
|
||||
abort();
|
||||
}
|
||||
o->next = options_strdup_list;
|
||||
options_strdup_list = o;
|
||||
strcpy(o->s, s);
|
||||
|
||||
return o->s;
|
||||
}
|
||||
|
||||
void option_add(int short_option, const char *long_option, int parameter_count)
|
||||
{
|
||||
option_t *option;
|
||||
|
@ -158,7 +179,7 @@ int options_config_file(const char *config_file, int (*handle_options)(int short
|
|||
param[j++] = *p++;
|
||||
}
|
||||
param[j] = '\0';
|
||||
argv[i] = strdup(param);
|
||||
argv[i] = options_strdup(param);
|
||||
sprintf(strchr(params, '\0'), " '%s'", param);
|
||||
/* skip white spaces behind option */
|
||||
while (*p > '\0' && *p <= ' ')
|
||||
|
@ -273,3 +294,21 @@ int option_is_first(void)
|
|||
return first_option;
|
||||
}
|
||||
|
||||
void options_free(void)
|
||||
{
|
||||
while (options_strdup_list) {
|
||||
struct options_strdup_entry *o;
|
||||
o = options_strdup_list;
|
||||
options_strdup_list = o->next;
|
||||
free(o);
|
||||
}
|
||||
|
||||
while (option_head) {
|
||||
option_t *o;
|
||||
o = option_head;
|
||||
option_head = o->next;
|
||||
free(o);
|
||||
}
|
||||
option_tailp = &option_head;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
char *options_strdup(const char *s);
|
||||
void option_add(int short_option, const char *long_option, int parameter_count);
|
||||
int options_config_file(const char *config_file, int (*handle_options)(int short_option, int argi, char *argv[]));
|
||||
int options_command_line(int argc, char *argv[], int (*handle_options)(int short_option, int argi, char *argv[]));
|
||||
int option_is_first(void);
|
||||
void options_free(void);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <inttypes.h>
|
||||
#include "../libtimer/timer.h"
|
||||
#include "../libdebug/debug.h"
|
||||
#include "../liboptions/options.h"
|
||||
#include "endpoint.h"
|
||||
|
||||
#define NTP_OFFSET 2208988800
|
||||
|
@ -38,7 +39,7 @@ void osmo_cc_set_local_peer(enum osmo_cc_session_nettype nettype, enum osmo_cc_s
|
|||
{
|
||||
default_nettype = nettype;
|
||||
default_addrtype = addrtype;
|
||||
default_unicast_address = strdup(address);
|
||||
default_unicast_address = options_strdup(address);
|
||||
}
|
||||
|
||||
osmo_cc_session_t *osmo_cc_new_session(void *priv, const char *username, const char *sess_id, const char *sess_version, enum osmo_cc_session_nettype nettype, enum osmo_cc_session_addrtype addrtype, const char *unicast_address, const char *session_name, int debug)
|
||||
|
|
|
@ -175,13 +175,13 @@ int sdr_config_handle_options(int short_option, int argi, char **argv)
|
|||
sdr_config->channel = atoi(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_DEVICE_ARGS:
|
||||
sdr_config->device_args = strdup(argv[argi]);
|
||||
sdr_config->device_args = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_STREAM_ARGS:
|
||||
sdr_config->stream_args = strdup(argv[argi]);
|
||||
sdr_config->stream_args = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_TUNE_ARGS:
|
||||
sdr_config->tune_args = strdup(argv[argi]);
|
||||
sdr_config->tune_args = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_SAMPLERATE:
|
||||
sdr_config->samplerate = atoi(argv[argi]);
|
||||
|
@ -193,13 +193,13 @@ int sdr_config_handle_options(int short_option, int argi, char **argv)
|
|||
sdr_config->bandwidth = atof(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_RX_ANTENNA:
|
||||
sdr_config->rx_antenna = strdup(argv[argi]);
|
||||
sdr_config->rx_antenna = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_TX_ANTENNA:
|
||||
sdr_config->tx_antenna = strdup(argv[argi]);
|
||||
sdr_config->tx_antenna = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_CLOCK_SOURCE:
|
||||
sdr_config->clock_source = strdup(argv[argi]);
|
||||
sdr_config->clock_source = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_RX_GAIN:
|
||||
sdr_config->rx_gain = atof(argv[argi]);
|
||||
|
@ -208,16 +208,16 @@ int sdr_config_handle_options(int short_option, int argi, char **argv)
|
|||
sdr_config->tx_gain = atof(argv[argi]);
|
||||
break;
|
||||
case OPT_WRITE_IQ_RX_WAVE:
|
||||
sdr_config->write_iq_rx_wave = strdup(argv[argi]);
|
||||
sdr_config->write_iq_rx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_WRITE_IQ_TX_WAVE:
|
||||
sdr_config->write_iq_tx_wave = strdup(argv[argi]);
|
||||
sdr_config->write_iq_tx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_READ_IQ_RX_WAVE:
|
||||
sdr_config->read_iq_rx_wave = strdup(argv[argi]);
|
||||
sdr_config->read_iq_rx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_READ_IQ_TX_WAVE:
|
||||
sdr_config->read_iq_tx_wave = strdup(argv[argi]);
|
||||
sdr_config->read_iq_tx_wave = options_strdup(argv[argi]);
|
||||
break;
|
||||
case OPT_SDR_SWAP_LINKS:
|
||||
sdr_config->swap_links = 1;
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <SoapySDR/Formats.h>
|
||||
#include "soapy.h"
|
||||
#include "../libdebug/debug.h"
|
||||
#include "../liboptions/options.h"
|
||||
|
||||
extern int sdr_rx_overflow;
|
||||
|
||||
|
@ -40,7 +41,7 @@ static uint64_t tx_count = 0;
|
|||
|
||||
static int parse_args(SoapySDRKwargs *args, const char *_args_string)
|
||||
{
|
||||
char *args_string = strdup(_args_string), *key, *val;
|
||||
char *args_string = options_strdup(_args_string), *key, *val;
|
||||
|
||||
memset(args, 0, sizeof(*args));
|
||||
while (args_string && *args_string) {
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <uhd/usrp/usrp.h>
|
||||
#include "uhd.h"
|
||||
#include "../libdebug/debug.h"
|
||||
#include "../liboptions/options.h"
|
||||
|
||||
/* use to TX time stamp */
|
||||
//#define TX_TIMESTAMP
|
||||
|
@ -246,7 +247,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args,
|
|||
} else
|
||||
tune_request.rf_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO;
|
||||
tune_request.dsp_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO;
|
||||
tune_request.args = strdup(_tune_args);
|
||||
tune_request.args = options_strdup(_tune_args);
|
||||
error = uhd_usrp_set_tx_freq(usrp, &tune_request, channel, &tune_result);
|
||||
if (error) {
|
||||
PDEBUG(DUHD, DEBUG_ERROR, "Failed to set TX frequency to %.0f Hz\n", tx_frequency);
|
||||
|
@ -291,7 +292,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args,
|
|||
memset(&stream_args, 0, sizeof(stream_args));
|
||||
stream_args.cpu_format = "fc32";
|
||||
stream_args.otw_format = "sc16";
|
||||
stream_args.args = strdup(_stream_args);
|
||||
stream_args.args = options_strdup(_stream_args);
|
||||
stream_args.channel_list = &channel;
|
||||
stream_args.n_channels = 1;
|
||||
error = uhd_usrp_get_tx_stream(usrp, &stream_args, tx_streamer);
|
||||
|
@ -434,7 +435,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args,
|
|||
} else
|
||||
tune_request.rf_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO;
|
||||
tune_request.dsp_freq_policy = UHD_TUNE_REQUEST_POLICY_AUTO;
|
||||
tune_request.args = strdup(_tune_args);
|
||||
tune_request.args = options_strdup(_tune_args);
|
||||
error = uhd_usrp_set_rx_freq(usrp, &tune_request, channel, &tune_result);
|
||||
if (error) {
|
||||
PDEBUG(DUHD, DEBUG_ERROR, "Failed to set RX frequency to %.0f Hz\n", rx_frequency);
|
||||
|
@ -479,7 +480,7 @@ int uhd_open(size_t channel, const char *_device_args, const char *_stream_args,
|
|||
memset(&stream_args, 0, sizeof(stream_args));
|
||||
stream_args.cpu_format = "fc32";
|
||||
stream_args.otw_format = "sc16";
|
||||
stream_args.args = strdup(_stream_args);
|
||||
stream_args.args = options_strdup(_stream_args);
|
||||
stream_args.channel_list = &channel;
|
||||
stream_args.n_channels = 1;
|
||||
error = uhd_usrp_get_rx_stream(usrp, &stream_args, rx_streamer);
|
||||
|
|
|
@ -197,7 +197,7 @@ void *sound_open(const char *audiodev, double __attribute__((unused)) *tx_freque
|
|||
return NULL;
|
||||
}
|
||||
|
||||
sound->audiodev = strdup(audiodev);
|
||||
sound->audiodev = strdup(audiodev); // is feed when closed
|
||||
sound->channels = channels;
|
||||
sound->samplerate = samplerate;
|
||||
sound->spl_deviation = max_deviation / 32767.0;
|
||||
|
|
Loading…
Reference in New Issue