MT#55283 use g_auto for string buffers

Change-Id: I135f75355a128feb8f3152c170ca4f9022d917a8
pull/1759/head
Richard Fuchs 2 years ago
parent 43d1427b4d
commit 5a2819bd9d

@ -1084,7 +1084,7 @@ int __init_stream(struct packet_stream *ps) {
struct call_media *media = ps->media;
struct call *call = ps->call;
int dtls_active = -1;
AUTO_CLEANUP_GBUF(paramsbuf);
g_autoptr(char) paramsbuf = NULL;
struct dtls_connection *dtls_conn = NULL;
if (MEDIA_ISSET(media, DTLS)) {

@ -4675,8 +4675,8 @@ void codec_tracker_update(struct codec_store *cs) {
if (!is_codec_touched_rate(sct, clockrate))
continue;
AUTO_CLEANUP_GBUF(pt_s);
pt_s = g_strdup_printf(STR_FORMAT "/%u", STR_FMT(supp_codec), clockrate);
g_autoptr(char) pt_s
= g_strdup_printf(STR_FORMAT "/%u", STR_FMT(supp_codec), clockrate);
str pt_str = STR_INIT(pt_s);
struct rtp_payload_type *pt = codec_add_payload_type(&pt_str, cs->media, NULL, NULL);

@ -97,7 +97,7 @@ static uint64_t jr_str_int(JsonReader *r) {
static struct call_monologue *janus_get_monologue(uint64_t handle_id, struct call *call,
struct call_monologue *(*fn)(struct call *, const str *))
{
AUTO_CLEANUP_GBUF(handle_buf);
g_autoptr(char) handle_buf = NULL;
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
str handle_str = STR_INIT(handle_buf);
@ -1592,7 +1592,7 @@ static const char *janus_trickle(JsonReader *reader, struct janus_session *sessi
// fetch call
AUTO_CLEANUP_GBUF(call_id);
g_autoptr(char) call_id = NULL;
AUTO_CLEANUP_NULL(struct call *call, call_unlock_release);
{
LOCK(&janus_lock);
@ -1645,7 +1645,7 @@ static const char *janus_trickle(JsonReader *reader, struct janus_session *sessi
// set required signalling flags
flags.fragment = 1;
AUTO_CLEANUP_GBUF(handle_buf);
g_autoptr(char) handle_buf = NULL;
handle_buf = g_strdup_printf("%" PRIu64, handle_id);
bencode_strdup_str(&ngbuf->buffer, &flags.from_tag, handle_buf);
bencode_strdup_str(&ngbuf->buffer, &flags.call_id, call_id);

@ -458,41 +458,41 @@ static void options(int *argc, char ***argv) {
AUTO_CLEANUP_GVBUF(listenngs);
AUTO_CLEANUP_GVBUF(listenngtcps);
AUTO_CLEANUP_GVBUF(listencli);
AUTO_CLEANUP_GBUF(graphitep);
AUTO_CLEANUP_GBUF(graphite_prefix_s);
AUTO_CLEANUP_GBUF(redisps);
AUTO_CLEANUP_GBUF(redisps_write);
AUTO_CLEANUP_GBUF(log_facility_cdr_s);
AUTO_CLEANUP_GBUF(log_facility_rtcp_s);
AUTO_CLEANUP_GBUF(log_facility_dtmf_s);
AUTO_CLEANUP_GBUF(log_format);
g_autoptr(char) graphitep = NULL;
g_autoptr(char) graphite_prefix_s = NULL;
g_autoptr(char) redisps = NULL;
g_autoptr(char) redisps_write = NULL;
g_autoptr(char) log_facility_cdr_s = NULL;
g_autoptr(char) log_facility_rtcp_s = NULL;
g_autoptr(char) log_facility_dtmf_s = NULL;
g_autoptr(char) log_format = NULL;
bool sip_source = false;
AUTO_CLEANUP_GBUF(homerp);
AUTO_CLEANUP_GBUF(homerproto);
g_autoptr(char) homerp = NULL;
g_autoptr(char) homerproto = NULL;
char *endptr;
bool codecs = false;
double max_load = 0;
double max_cpu = 0;
AUTO_CLEANUP_GBUF(dtmf_udp_ep);
AUTO_CLEANUP_GBUF(endpoint_learning);
AUTO_CLEANUP_GBUF(dtls_sig);
g_autoptr(char) dtmf_udp_ep = NULL;
g_autoptr(char) endpoint_learning = NULL;
g_autoptr(char) dtls_sig = NULL;
double silence_detect = 0;
AUTO_CLEANUP_GVBUF(cn_payload);
AUTO_CLEANUP_GVBUF(dtx_cn_params);
bool debug_srtp = false;
AUTO_CLEANUP_GBUF(amr_dtx);
g_autoptr(char) amr_dtx = NULL;
#ifdef HAVE_MQTT
AUTO_CLEANUP_GBUF(mqtt_publish_scope);
g_autoptr(char) mqtt_publish_scope = NULL;
#endif
AUTO_CLEANUP_GBUF(mos);
AUTO_CLEANUP_GBUF(dcc);
AUTO_CLEANUP_GBUF(use_audio_player);
AUTO_CLEANUP_GBUF(control_pmtu);
g_autoptr(char) mos = NULL;
g_autoptr(char) dcc = NULL;
g_autoptr(char) use_audio_player = NULL;
g_autoptr(char) control_pmtu = NULL;
#ifndef WITHOUT_NFTABLES
bool nftables_start = false;
bool nftables_stop = false;
bool nftables_status = false;
AUTO_CLEANUP_GBUF(nftables_family);
g_autoptr(char) nftables_family = NULL;
#endif
rwlock_lock_w(&rtpe_config.config_lock);

@ -1132,7 +1132,7 @@ err:
// call->master_lock held in W
int media_player_play_db(struct media_player *mp, long long id, long long repeat, long long start_pos) {
const char *err;
AUTO_CLEANUP_GBUF(query);
g_autoptr(char) query = NULL;
err = "missing configuration";
if (!rtpe_config.mysql_host || !rtpe_config.mysql_query)

@ -857,7 +857,7 @@ static void finish_proc(struct call *call, bool discard) {
}
const char *unlink_fn = recording->proc.meta_filepath;
AUTO_CLEANUP_GBUF(discard_fn);
g_autoptr(char) discard_fn = NULL;
if (discard) {
discard_fn = g_strdup_printf("%s.DISCARD", recording->proc.meta_filepath);
int ret = rename(recording->proc.meta_filepath, discard_fn);

@ -484,10 +484,10 @@ GQueue *statistics_gather_metrics(struct interface_sampled_rate_stats *interface
double min = (double) atomic64_get(&rtpe_sampled_graphite_min_max_sampled.min.ng_command_times[i]) / 1000000.0;
double max = (double) atomic64_get(&rtpe_sampled_graphite_min_max_sampled.max.ng_command_times[i]) / 1000000.0;
double avg = (double) atomic64_get(&rtpe_sampled_graphite_avg.avg.ng_command_times[i]) / 1000000.0;
AUTO_CLEANUP(char *min_label, free_gbuf) = g_strdup_printf("min%sdelay", ng_command_strings[i]);
AUTO_CLEANUP(char *max_label, free_gbuf) = g_strdup_printf("max%sdelay", ng_command_strings[i]);
AUTO_CLEANUP(char *avg_label, free_gbuf) = g_strdup_printf("avg%sdelay", ng_command_strings[i]);
AUTO_CLEANUP(char *long_label, free_gbuf) = g_strdup_printf("Min/Max/Avg %s processing delay", ng_command_strings[i]);
g_autoptr(char) min_label = g_strdup_printf("min%sdelay", ng_command_strings[i]);
g_autoptr(char) max_label = g_strdup_printf("max%sdelay", ng_command_strings[i]);
g_autoptr(char) avg_label = g_strdup_printf("avg%sdelay", ng_command_strings[i]);
g_autoptr(char) long_label = g_strdup_printf("Min/Max/Avg %s processing delay", ng_command_strings[i]);
METRICl(long_label, "%.6f/%.6f/%.6f sec", min, max, avg);
METRICsva(min_label, "%.6f", min);
METRICsva(max_label, "%.6f", max);
@ -498,10 +498,10 @@ GQueue *statistics_gather_metrics(struct interface_sampled_rate_stats *interface
uint64_t min = atomic64_get(&rtpe_rate_graphite_min_max_avg_sampled.min.ng_commands[i]);
uint64_t max = atomic64_get(&rtpe_rate_graphite_min_max_avg_sampled.max.ng_commands[i]);
uint64_t avg = atomic64_get(&rtpe_rate_graphite_min_max_avg_sampled.avg.ng_commands[i]);
AUTO_CLEANUP(char *min_label, free_gbuf) = g_strdup_printf("min%srequestrate", ng_command_strings[i]);
AUTO_CLEANUP(char *max_label, free_gbuf) = g_strdup_printf("max%srequestrate", ng_command_strings[i]);
AUTO_CLEANUP(char *avg_label, free_gbuf) = g_strdup_printf("avg%srequestrate", ng_command_strings[i]);
AUTO_CLEANUP(char *long_label, free_gbuf) = g_strdup_printf("Min/Max/Avg %s requests per second", ng_command_strings[i]);
g_autoptr(char) min_label = g_strdup_printf("min%srequestrate", ng_command_strings[i]);
g_autoptr(char) max_label = g_strdup_printf("max%srequestrate", ng_command_strings[i]);
g_autoptr(char) avg_label = g_strdup_printf("avg%srequestrate", ng_command_strings[i]);
g_autoptr(char) long_label = g_strdup_printf("Min/Max/Avg %s requests per second", ng_command_strings[i]);
METRICl(long_label, "%" PRIu64 "/%" PRIu64 "/%" PRIu64 " per sec", min, max, avg);
METRICsva(min_label, "%" PRIu64 "", min);
METRICsva(max_label, "%" PRIu64 "", max);

@ -176,7 +176,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char
{
AUTO_CLEANUP_NULL(GOptionContext *c, free_goptc);
AUTO_CLEANUP_NULL(GError *er, free_gerror);
AUTO_CLEANUP_GBUF(use_section);
g_autoptr(char) use_section = NULL;
const char *use_config;
int fatal = 0;
AUTO_CLEANUP(char **saved_argv, free_gvbuf) = g_strdupv(*argv);
@ -465,10 +465,6 @@ int timeval_cmp_ptr(const void *a, const void *b) {
return 0;
}
void free_gbuf(char **p) {
g_free(*p);
}
void free_gvbuf(char ***p) {
g_strfreev(*p);
}

@ -78,13 +78,12 @@ int num_cpu_cores(int);
#define UINT64F "%" G_GUINT64_FORMAT
void free_gbuf(char **);
void free_gvbuf(char ***);
#define AUTO_CLEANUP(decl, func) decl __attribute__ ((__cleanup__(func)))
#define AUTO_CLEANUP_INIT(decl, func, val) AUTO_CLEANUP(decl, func) = val
#define AUTO_CLEANUP_NULL(decl, func) AUTO_CLEANUP_INIT(decl, func, 0)
#define AUTO_CLEANUP_GBUF(var) AUTO_CLEANUP_NULL(char *var, free_gbuf)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(char, g_free)
#define AUTO_CLEANUP_GVBUF(var) AUTO_CLEANUP_NULL(char **var, free_gvbuf)

@ -142,7 +142,7 @@ static void log_both(int facility_priority, const char *format, ...) {
void __vpilog(int prio, const char *prefix, const char *fmt, va_list ap) {
AUTO_CLEANUP_GBUF(msg);
g_autoptr(char) msg = NULL;
char *piece;
const char *infix = "";
int len, xprio;

@ -655,7 +655,7 @@ static char *start_dump_stream(struct stream *s, const char *suffix) {
s->fmtctx = avformat_alloc_context();
if (!s->fmtctx)
goto out;
AUTO_CLEANUP(char *fn, free_gbuf)
g_autoptr(char) fn
= g_strdup_printf("stream-dump-%llu%s.mkv",
(long long unsigned) time(NULL),
suffix ?: "");
@ -1007,7 +1007,7 @@ static bool thread_collect(pid_t pid, struct stats *outp, struct stats_sample *s
if (!pid)
return false;
AUTO_CLEANUP(char *fn, free_gbuf)
g_autoptr(char) fn
= g_strdup_printf("/proc/%i/task/%i/stat", (int) pid, (int) pid);
AUTO_CLEANUP(FILE *fp, fclose_p) = fopen(fn, "r");
if (!fp)
@ -1212,7 +1212,7 @@ static int pid_compare(const void *a, const void *b) {
static int other_threads_collect(const bool do_output, int starty, int maxy, int maxx,
struct stats *totals)
{
AUTO_CLEANUP(char *dn, free_gbuf) = g_strdup_printf("/proc/%u/task", getpid());
g_autoptr(char) dn = g_strdup_printf("/proc/%u/task", getpid());
AUTO_CLEANUP(DIR *dp, closedir_p) = opendir(dn);
if (!dp)
return starty;
@ -1421,7 +1421,7 @@ static char *fixture_path_file(const char *base_fn) {
static void fixture_read_avio(GPtrArray *fixture, struct testparams *prm) {
AVFormatContext *fctx = NULL;
AUTO_CLEANUP(char *fn, free_gbuf) = fixture_path_file(prm->file);
g_autoptr(char) fn = fixture_path_file(prm->file);
int ret = avformat_open_input(&fctx, fn, NULL, NULL);
if (ret < 0)
die("Failed to open input fixture");
@ -1450,7 +1450,7 @@ static void fixture_read_avio(GPtrArray *fixture, struct testparams *prm) {
static void fixture_read_raw(GPtrArray *fixture, struct testparams *prm) {
AUTO_CLEANUP(char *fn, free_gbuf) = fixture_path_file(prm->file);
g_autoptr(char) fn = fixture_path_file(prm->file);
FILE *fp = fopen(fn, "r");
if (!fp)
die("Failed to open input fixture");
@ -1663,7 +1663,7 @@ static void *cpu_freq_monitor(void *p) {
if (strncmp(ent->d_name, "policy", 6) != 0)
continue; // skip
AUTO_CLEANUP(char *fn, free_gbuf)
g_autoptr(char) fn
= g_strdup_printf("/sys/devices/system/cpu/cpufreq/%s/scaling_cur_freq",
ent->d_name);
AUTO_CLEANUP(FILE *fp, fclose_p) = fopen(fn, "r");

@ -183,12 +183,12 @@ static mode_t chmod_parse(const char *s) {
static void options(int *argc, char ***argv) {
AUTO_CLEANUP_GBUF(os_str);
AUTO_CLEANUP_GBUF(chmod_mode);
AUTO_CLEANUP_GBUF(chmod_dir_mode);
AUTO_CLEANUP_GBUF(user_uid);
AUTO_CLEANUP_GBUF(group_gid);
AUTO_CLEANUP_GBUF(mix_method_str);
g_autoptr(char) os_str = NULL;
g_autoptr(char) chmod_mode = NULL;
g_autoptr(char) chmod_dir_mode = NULL;
g_autoptr(char) user_uid = NULL;
g_autoptr(char) group_gid = NULL;
g_autoptr(char) mix_method_str = NULL;
GOptionEntry e[] = {
{ "table", 't', 0, G_OPTION_ARG_INT, &ktable, "Kernel table rtpengine uses", "INT" },

Loading…
Cancel
Save