From 5edc8973ebdb2f80e1fa5b9c7b0ea7d12fd2fe3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 5 Sep 2024 22:14:28 +0200 Subject: [PATCH] various: use talloc_replace --- input/input.c | 3 +-- options/m_option.c | 6 ++---- player/osd.c | 9 +++------ video/out/vo_gpu_next.c | 6 ++---- video/out/wayland_common.c | 4 +--- video/out/x11_common.c | 3 +-- 6 files changed, 10 insertions(+), 21 deletions(-) diff --git a/input/input.c b/input/input.c index 68bb2b0859..655b6717d5 100644 --- a/input/input.c +++ b/input/input.c @@ -1304,8 +1304,7 @@ void mp_input_define_section(struct input_ctx *ictx, char *name, char *location, if ((!bs->owner || (owner && strcmp(bs->owner, owner) != 0)) && !bstr_equals0(bs->section, "default")) { - talloc_free(bs->owner); - bs->owner = talloc_strdup(bs, owner); + talloc_replace(bs, bs->owner, owner); } remove_binds(bs, builtin); if (contents && contents[0]) { diff --git a/options/m_option.c b/options/m_option.c index 64e383936f..a6f8bcd45c 100644 --- a/options/m_option.c +++ b/options/m_option.c @@ -1233,10 +1233,8 @@ static char *print_str(const m_option_t *opt, const void *val) static void copy_str(const m_option_t *opt, void *dst, const void *src) { - if (dst && src) { - talloc_free(VAL(dst)); - VAL(dst) = talloc_strdup(NULL, VAL(src)); - } + if (dst && src) + talloc_replace(NULL, VAL(dst), VAL(src)); } static int str_set(const m_option_t *opt, void *dst, struct mpv_node *src) diff --git a/player/osd.c b/player/osd.c index 6381b70d6e..3ed0dbeab0 100644 --- a/player/osd.c +++ b/player/osd.c @@ -116,8 +116,7 @@ void term_osd_set_subs(struct MPContext *mpctx, const char *text) text = ""; // disable if (strcmp(mpctx->term_osd_subs ? mpctx->term_osd_subs : "", text) == 0) return; - talloc_free(mpctx->term_osd_subs); - mpctx->term_osd_subs = talloc_strdup(mpctx, text); + talloc_replace(mpctx, mpctx->term_osd_subs, text); term_osd_update(mpctx); } @@ -126,14 +125,12 @@ static void term_osd_set_text_lazy(struct MPContext *mpctx, const char *text) bool video_osd = mpctx->video_out && mpctx->opts->video_osd; if ((video_osd && mpctx->opts->term_osd != 1) || !text) text = ""; // disable - talloc_free(mpctx->term_osd_text); - mpctx->term_osd_text = talloc_strdup(mpctx, text); + talloc_replace(mpctx, mpctx->term_osd_text, text); } static void term_osd_set_status_lazy(struct MPContext *mpctx, const char *text) { - talloc_free(mpctx->term_osd_status); - mpctx->term_osd_status = talloc_strdup(mpctx, text); + talloc_replace(mpctx, mpctx->term_osd_status, text); } static void add_term_osd_bar(struct MPContext *mpctx, char **line, int width) diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index 6e264223a2..d07472bdf6 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -2028,8 +2028,7 @@ static void update_icc_opts(struct priv *p, const struct mp_icc_opts *opts) update_icc(p, icc); // Update cached path - talloc_free(p->icc_path); - p->icc_path = talloc_strdup(p, opts->profile); + talloc_replace(p, p->icc_path, opts->profile); } static void update_lut(struct priv *p, struct user_lut *lut) @@ -2045,8 +2044,7 @@ static void update_lut(struct priv *p, struct user_lut *lut) // Update cached path pl_lut_free(&lut->lut); - talloc_free(lut->path); - lut->path = talloc_strdup(p, lut->opt); + talloc_replace(p, lut->path, lut->opt); // Load LUT file char *fname = mp_get_user_path(NULL, p->global, lut->path); diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index ce2b353938..ba2131c465 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -655,9 +655,7 @@ static void data_offer_handle_offer(void *data, struct wl_data_offer *offer, int score = mp_event_get_mime_type_score(wl->vo->input_ctx, mime_type); if (score > wl->dnd_mime_score && wl->opts->drag_and_drop != -2) { wl->dnd_mime_score = score; - if (wl->dnd_mime_type) - talloc_free(wl->dnd_mime_type); - wl->dnd_mime_type = talloc_strdup(wl, mime_type); + talloc_replace(wl, wl->dnd_mime_type, mime_type); MP_VERBOSE(wl, "Given DND offer with mime type %s\n", wl->dnd_mime_type); } } diff --git a/video/out/x11_common.c b/video/out/x11_common.c index e1d094f582..ae1ea5bf46 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -2229,8 +2229,7 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg) set_screensaver(x11, true); return VO_TRUE; case VOCTRL_UPDATE_WINDOW_TITLE: - talloc_free(x11->window_title); - x11->window_title = talloc_strdup(x11, (char *)arg); + talloc_replace(x11, x11->window_title, (char *)arg); if (!x11->parent || x11->opts->x11_wid_title) vo_x11_update_window_title(vo); return VO_TRUE;