Skip to content

Commit

Permalink
various: use talloc_replace
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper93 committed Sep 8, 2024
1 parent 3edbd30 commit 5edc897
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 21 deletions.
3 changes: 1 addition & 2 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
6 changes: 2 additions & 4 deletions options/m_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions player/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions video/out/vo_gpu_next.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 1 addition & 2 deletions video/out/x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5edc897

Please sign in to comment.