From a4849f7ae6f6cf6f954ac61ea1ce500c3ff74b99 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 11 Jun 2020 11:39:18 -0400 Subject: [PATCH] TT#28300 eliminate need for if_a_global Change-Id: I4b1c23d9a08b68bd722e14d7077198ddbaefc2e0 --- daemon/main.c | 14 +++----------- lib/str.h | 7 +++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index f59d4d48c..9c61980c6 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -73,8 +73,6 @@ struct rtpengine_config rtpe_config = { .dtls_signature = 256, }; -char **if_a_global = NULL; - static void sighandler(gpointer x) { sigset_t ss; int ret; @@ -159,11 +157,11 @@ static int if_addr_parse(GQueue *q, char *s, struct ifaddrs *ifas) { c = strchr(s, '/'); if (c) { *c++ = 0; - str_init(&name, s); + str_init_dup(&name, s); s = c; } else - str_init(&name, "default"); + str_init_dup(&name, "default"); /* advertised address */ c = strchr(s, '!'); @@ -285,7 +283,7 @@ static int redis_ep_parse(endpoint_t *ep, int *db, char **auth, const char *auth static void options(int *argc, char ***argv) { - char **if_a = NULL; + AUTO_CLEANUP_GVBUF(if_a); AUTO_CLEANUP_GVBUF(ks_a); unsigned long uint_keyspace_db; str str_keyspace_db; @@ -603,9 +601,6 @@ static void options(int *argc, char ***argv) { if (rtpe_config.jb_length < 0) die("Invalid negative jitter buffer size"); - - // free local vars - if_a_global = if_a; // -> content is used; needs to be freed later } void fill_initial_rtpe_cfg(struct rtpengine_config* ini_rtpe_cfg) { @@ -709,9 +704,6 @@ static void options_free(void) { // free common config options config_load_free(&rtpe_config.common); - - // free if_a STRING LIST - g_strfreev(if_a_global); } static void early_init(void) { diff --git a/lib/str.h b/lib/str.h index 4ced69171..9ebc36ddc 100644 --- a/lib/str.h +++ b/lib/str.h @@ -60,6 +60,8 @@ INLINE str *str_init(str *out, char *s); INLINE str *str_init_len(str *out, char *s, int len); INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len); #define str_init_len_assert(out, s, len) str_init_len_assert_len(out, s, sizeof(s), len) +/* inits a str object from a regular string and duplicates the contents. returns out */ +INLINE str *str_init_dup(str *out, char *s); /* returns new str object with uninitialized buffer large enough to hold `len` characters (+1 for null byte) */ INLINE str *str_alloc(int len); /* returns new str object allocated with malloc, including buffer */ @@ -228,6 +230,11 @@ INLINE str *str_init_len_assert_len(str *out, char *s, int buflen, int len) { assert(buflen >= len); return str_init_len(out, s, len); } +INLINE str *str_init_dup(str *out, char *s) { + out->s = s ? strdup(s) : NULL; + out->len = s ? strlen(s) : 0; + return out; +} INLINE str *str_alloc(int len) { str *r; r = malloc(sizeof(*r) + len + 1);