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.
pull/1/head
Andreas Eversberg 2 years ago
parent 22cb70fb1b
commit 8c0a25f3b0
  1. 2
      src/amps/amps_tacs_main.c
  2. 2
      src/anetz/main.c
  3. 8
      src/bnetz/dialer.c
  4. 4
      src/bnetz/main.c
  5. 4
      src/cnetz/main.c
  6. 14
      src/datenklo/main.c
  7. 2
      src/eurosignal/main.c
  8. 5
      src/fuvst/fuvst.c
  9. 2
      src/fuvst/main.c
  10. 8
      src/imts/dialer.c
  11. 2
      src/imts/main.c
  12. 4
      src/jolly/main.c
  13. 3
      src/libdebug/debug.c
  14. 16
      src/libmobile/main_mobile.c
  15. 41
      src/liboptions/options.c
  16. 2
      src/liboptions/options.h
  17. 3
      src/libosmocc/session.c
  18. 20
      src/libsdr/sdr_config.c
  19. 3
      src/libsdr/soapy.c
  20. 9
      src/libsdr/uhd.c
  21. 2
      src/libsound/sound_alsa.c
  22. 4
      src/nmt/main.c
  23. 2
      src/r2000/main.c
  24. 10
      src/radio/main.c
  25. 24
      src/sim/main.c
  26. 2
      src/test/Makefile.am
  27. 6
      src/tv/main.c
  28. 2
      src/zeitansage/main.c

@ -402,6 +402,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -198,6 +198,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -125,16 +125,16 @@ static int handle_options(int short_option, int __attribute__((unused)) argi, ch
print_help(argv[0]);
return 0;
case 'i':
station_id = strdup(argv[argi]);
station_id = options_strdup(argv[argi]);
break;
case 'a':
audiodev = strdup(argv[argi]);
audiodev = options_strdup(argv[argi]);
break;
case 's':
samplerate = atoi(argv[argi]);
break;
case 'w':
write_tx_wave = strdup(argv[argi]);
write_tx_wave = options_strdup(argv[argi]);
break;
case 'g':
case OPT_METERING:
@ -390,6 +390,8 @@ exit:
/* exit fsk */
fsk_mod_cleanup(&fsk_mod);
options_free();
return 0;
}

@ -109,7 +109,7 @@ static int handle_options(int short_option, int argi, char **argv)
metering = atoi(argv[argi]);
break;
case 'P':
paging = strdup(argv[argi]);
paging = options_strdup(argv[argi]);
break;
case 'S':
if (!strcasecmp(argv[argi], "auto"))
@ -204,6 +204,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -376,7 +376,7 @@ error_fuz:
fuz_rest = atoi_limit(p, 0, 255);
} else
if (!strncasecmp(argv[argi], "fuz-name=", p - argv[argi])) {
fuz_name = strdup(p);
fuz_name = options_strdup(p);
} else
if (!strncasecmp(argv[argi], "kennung-fufst=", p - argv[argi])) {
kennung_fufst = atoi_limit(p, 0, 3);
@ -659,6 +659,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -194,13 +194,13 @@ static int handle_options(int short_option, int argi, char **argv)
OPT_ARRAY(num_tx_baudrate, tx_baudrate, atoi(argv[argi + 1]))
break;
case 'D':
OPT_ARRAY(num_ttydev, ttydev, strdup(argv[argi]))
OPT_ARRAY(num_ttydev, ttydev, options_strdup(argv[argi]))
break;
case 'S':
stereo = 1;
break;
case 'a':
audiodev = strdup(argv[argi]);
audiodev = options_strdup(argv[argi]);
break;
case 's':
samplerate = atoi(argv[argi]);
@ -215,16 +215,16 @@ static int 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;
}
@ -315,6 +315,8 @@ fail:
for (i = 0; i < num_kanal; i++)
datenklo_exit(&datenklo[i]);
options_free();
return 0;
}

@ -250,6 +250,8 @@ fail:
fm_exit();
euro_exit();
options_free();
return 0;
}

@ -36,6 +36,7 @@
#include <inttypes.h>
#include "../libsample/sample.h"
#include "../libdebug/debug.h"
#include "../liboptions/options.h"
#include "../libmobile/call.h"
#include "../libmobile/cause.h"
#include "../libtimer/timer.h"
@ -1157,7 +1158,7 @@ int fuvst_create(const char *kanal, enum fuvst_chan_type chan_type, const char *
/* init general part of transceiver */
/* do not enable emphasis, since it is done by fuvst code, not by common sender code */
rc = sender_create(&fuvst->sender, strdup(chan_name), 0, 0, audiodev, 0, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE);
rc = sender_create(&fuvst->sender, options_strdup(chan_name), 0, 0, audiodev, 0, samplerate, rx_gain, tx_gain, 0, 0, write_rx_wave, write_tx_wave, read_rx_wave, read_tx_wave, loopback, PAGING_SIGNAL_NONE);
if (rc < 0) {
PDEBUG(DCNETZ, DEBUG_ERROR, "Failed to init transceiver process!\n");
goto error;
@ -1169,7 +1170,7 @@ int fuvst_create(const char *kanal, enum fuvst_chan_type chan_type, const char *
if (fuvst->chan_type == CHAN_TYPE_ZZK) {
/* create link */
rc = mtp_init(&fuvst->mtp, strdup(chan_name), fuvst, mtp_receive, 4800, ignore_link_monitor, sio, local_pc, remote_pc);
rc = mtp_init(&fuvst->mtp, options_strdup(chan_name), fuvst, mtp_receive, 4800, ignore_link_monitor, sio, local_pc, remote_pc);
if (rc < 0)
goto error;
/* power on stack */

@ -276,6 +276,8 @@ fail:
// zeit_exit();
fm_exit();
options_free();
return 0;
}

@ -106,16 +106,16 @@ static int handle_options(int short_option, int __attribute__((unused)) argi, ch
print_help(argv[0]);
return 0;
case 'i':
station_id = strdup(argv[argi]);
station_id = options_strdup(argv[argi]);
break;
case 'a':
audiodev = strdup(argv[argi]);
audiodev = options_strdup(argv[argi]);
break;
case 's':
samplerate = atoi(argv[argi]);
break;
case 'w':
write_tx_wave = strdup(argv[argi]);
write_tx_wave = options_strdup(argv[argi]);
break;
default:
return -EINVAL;
@ -348,6 +348,8 @@ exit:
sound_close(audio);
#endif
options_free();
return 0;
}

@ -284,6 +284,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -87,7 +87,7 @@ static int handle_options(int short_option, int argi, char **argv)
switch (short_option) {
case 'F':
string = strdup(argv[argi]);
string = options_strdup(argv[argi]);
string_dl = strsep(&string, ",");
string_ul = strsep(&string, ",");
string_step = strsep(&string, ",");
@ -208,6 +208,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -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;

@ -202,7 +202,7 @@ error_ta:
OPT_ARRAY(num_supervisory, supervisory, super)
break;
case 'S':
smsc_number = strdup(argv[argi]);
smsc_number = options_strdup(argv[argi]);
break;
case 'I':
send_callerid = atoi(argv[argi]);
@ -422,6 +422,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -373,6 +373,8 @@ fail:
/* exits */
fm_exit();
options_free();
return 0;
}

@ -192,14 +192,14 @@ static int handle_options(int short_option, int argi, char **argv)
samplerate = atof(argv[argi]);
break;
case 'r':
tx_wave_file = strdup(argv[argi]);
tx_wave_file = options_strdup(argv[argi]);
break;
case 'w':
rx_wave_file = strdup(argv[argi]);
rx_wave_file = options_strdup(argv[argi]);
break;
case 'a':
tx_audiodev = strdup(argv[argi]);
rx_audiodev = strdup(argv[argi]);
tx_audiodev = options_strdup(argv[argi]);
rx_audiodev = options_strdup(argv[argi]);
break;
case 'M':
if (!strcasecmp(argv[argi], "fm"))
@ -516,6 +516,8 @@ error:
fm_exit();
am_exit();
options_free();
return 0;
}

@ -148,42 +148,42 @@ int handle_options(int short_option, int argi, char **argv)
}
break;
case 's':
serialdev = strdup(argv[argi]);
serialdev = options_strdup(argv[argi]);
break;
case 'b':
baudrate = atoi(argv[argi]);
break;
case 'E':
eeprom_name = strdup(argv[argi]);
eeprom_name = options_strdup(argv[argi]);
break;
case 'F':
futln = strdup(argv[argi]);
futln = options_strdup(argv[argi]);
break;
case OPT_SICHERUNG:
sicherung = strdup(argv[argi]);
sicherung = options_strdup(argv[argi]);
break;
case OPT_KARTEN:
karten = strdup(argv[argi]);
karten = options_strdup(argv[argi]);
break;
case OPT_SONDER:
sonder = strdup(argv[argi]);
sonder = options_strdup(argv[argi]);
break;
case OPT_WARTUNG:
wartung = strdup(argv[argi]);
wartung = options_strdup(argv[argi]);
break;
case 'P':
pin = strdup(argv[argi]);
pin = options_strdup(argv[argi]);
break;
case 'D':
if (dir_count == MAX_DIR_COUNT)
break;
dir_location[dir_count] = atoi(argv[argi + 0]);
dir_number[dir_count] = strdup(argv[argi + 1]);
dir_name[dir_count] = strdup(argv[argi + 2]);
dir_number[dir_count] = options_strdup(argv[argi + 1]);
dir_name[dir_count] = options_strdup(argv[argi + 2]);
dir_count++;
break;
case 'A':
auth = strdup(argv[argi]);
auth = options_strdup(argv[argi]);
break;
default:
return -EINVAL;
@ -491,6 +491,8 @@ error:
if (serial)
serial_close(serial);
options_free();
return 0;
}

@ -18,6 +18,7 @@ test_filter_LDADD = \
$(COMMON_LA) \
$(top_builddir)/src/libdebug/libdebug.a \
$(top_builddir)/src/libfilter/libfilter.a \
$(top_builddir)/src/liboptions/liboptions.a \
-lm
test_sendevolumenregler_SOURCES = test_sendevolumenregler.c
@ -41,6 +42,7 @@ test_emphasis_LDADD = \
$(top_builddir)/src/libdebug/libdebug.a \
$(top_builddir)/src/libemphasis/libemphasis.a \
$(top_builddir)/src/libfilter/libfilter.a \
$(top_builddir)/src/liboptions/liboptions.a \
-lm
test_dtmf_SOURCES = dummy.x test_dtmf.c

@ -184,7 +184,7 @@ static int handle_options(int short_option, int argi, char **argv)
samplerate = atof(argv[argi]);
break;
case 'w':
wave_file = strdup(argv[argi]);
wave_file = options_strdup(argv[argi]);
break;
case 'r':
rt_prio = atoi(argv[argi]);
@ -208,7 +208,7 @@ static int handle_options(int short_option, int argi, char **argv)
grid_width = atoi(argv[argi]);
break;
case 'I':
station_id = strdup(argv[argi]);
station_id = options_strdup(argv[argi]);
if (strlen(station_id) != 12) {
fprintf(stderr, "Given station ID must be exactly 12 characters long. (Use spaces to fill it.)\n");
return -EINVAL;
@ -535,6 +535,8 @@ int main(int argc, char *argv[])
/* exits */
fm_exit();
options_free();
return 0;
}

@ -100,6 +100,8 @@ int main(int argc, char *argv[])
zeit_exit();
fm_exit();
options_free();
return 0;
}

Loading…
Cancel
Save