commands: change property mechanism to use talloc strings

This commit is contained in:
Uoti Urpala 2011-07-03 20:04:21 +03:00
parent 774bb252aa
commit c5364305be
7 changed files with 91 additions and 140 deletions

115
command.c
View File

@ -277,9 +277,9 @@ static int mp_property_loop(m_option_t *prop, int action, void *arg,
case M_PROPERTY_PRINT:
if (!arg) return M_PROPERTY_ERROR;
if (opts->loop_times < 0)
*(char**)arg = strdup("off");
*(char**)arg = talloc_strdup(NULL, "off");
else if (opts->loop_times == 0)
*(char**)arg = strdup("inf");
*(char**)arg = talloc_strdup(NULL, "inf");
else
break;
return M_PROPERTY_OK;
@ -563,7 +563,6 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
struct MPOpts *opts = &mpctx->opts;
int angle = -1;
int angles;
char *angle_name = NULL;
if (mpctx->demuxer)
angle = demuxer_get_current_angle(mpctx->demuxer);
@ -582,11 +581,7 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
case M_PROPERTY_PRINT: {
if (!arg)
return M_PROPERTY_ERROR;
angle_name = calloc(1, 64);
if (!angle_name)
return M_PROPERTY_UNAVAILABLE;
snprintf(angle_name, 64, "%d/%d", angle, angles);
*(char **) arg = angle_name;
*(char **) arg = talloc_asprintf(NULL, "%d/%d", angle, angles);
return M_PROPERTY_OK;
}
case M_PROPERTY_SET:
@ -626,7 +621,6 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
"Angle: %d/%d", angle, angles);
free(angle_name);
return M_PROPERTY_OK;
}
@ -783,7 +777,7 @@ static int mp_property_mute(m_option_t *prop, int action, void *arg,
if (!arg)
return M_PROPERTY_ERROR;
if (mpctx->edl_muted) {
*(char **) arg = strdup(mp_gtext("enabled (EDL)"));
*(char **) arg = talloc_strdup(NULL, mp_gtext("enabled (EDL)"));
return M_PROPERTY_OK;
}
default:
@ -852,8 +846,8 @@ static int mp_property_samplerate(m_option_t *prop, int action, void *arg,
switch(action) {
case M_PROPERTY_PRINT:
if(!arg) return M_PROPERTY_ERROR;
*(char**)arg = malloc(16);
sprintf(*(char**)arg,"%d kHz",mpctx->sh_audio->samplerate/1000);
*(char**)arg = talloc_asprintf(NULL, "%d kHz",
mpctx->sh_audio->samplerate/1000);
return M_PROPERTY_OK;
}
return m_property_int_ro(prop, action, arg, mpctx->sh_audio->samplerate);
@ -871,14 +865,14 @@ static int mp_property_channels(m_option_t *prop, int action, void *arg,
return M_PROPERTY_ERROR;
switch (mpctx->sh_audio->channels) {
case 1:
*(char **) arg = strdup("mono");
*(char **) arg = talloc_strdup(NULL, "mono");
break;
case 2:
*(char **) arg = strdup("stereo");
*(char **) arg = talloc_strdup(NULL, "stereo");
break;
default:
*(char **) arg = malloc(32);
sprintf(*(char **) arg, "%d channels", mpctx->sh_audio->channels);
*(char **) arg = talloc_asprintf(NULL, "%d channels",
mpctx->sh_audio->channels);
}
return M_PROPERTY_OK;
}
@ -906,15 +900,15 @@ static int mp_property_balance(m_option_t *prop, int action, void *arg,
return M_PROPERTY_ERROR;
mixer_getbalance(&mpctx->mixer, &bal);
if (bal == 0.f)
*str = strdup("center");
*str = talloc_strdup(NULL, "center");
else if (bal == -1.f)
*str = strdup("left only");
*str = talloc_strdup(NULL, "left only");
else if (bal == 1.f)
*str = strdup("right only");
*str = talloc_strdup(NULL, "right only");
else {
unsigned right = (bal + 1.f) / 2.f * 100.f;
*str = malloc(sizeof("left xxx%, right xxx%"));
sprintf(*str, "left %d%%, right %d%%", 100 - right, right);
*str = talloc_asprintf(NULL, "left %d%%, right %d%%",
100 - right, right);
}
return M_PROPERTY_OK;
}
@ -956,7 +950,7 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
return M_PROPERTY_ERROR;
if (current_id < 0)
*(char **) arg = strdup(mp_gtext("disabled"));
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
else {
char lang[40];
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
@ -978,8 +972,7 @@ static int mp_property_audio(m_option_t *prop, int action, void *arg,
else if (mpctx->stream->type == STREAMTYPE_DVDNAV)
mp_dvdnav_lang_from_aid(mpctx->stream, current_id, lang);
#endif
*(char **) arg = malloc(64);
snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
*(char **)arg = talloc_asprintf(NULL, "(%d) %s", current_id, lang);
}
return M_PROPERTY_OK;
@ -1028,12 +1021,10 @@ static int mp_property_video(m_option_t *prop, int action, void *arg,
return M_PROPERTY_ERROR;
if (current_id < 0)
*(char **) arg = strdup(mp_gtext("disabled"));
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
else {
char lang[40];
strncpy(lang, mp_gtext("unknown"), sizeof(lang));
*(char **) arg = malloc(64);
snprintf(*(char **) arg, 64, "(%d) %s", current_id, lang);
*(char **) arg = talloc_asprintf(NULL, "(%d) %s", current_id,
mp_gtext("unknown"));
}
return M_PROPERTY_OK;
@ -1178,9 +1169,9 @@ static int mp_property_yuv_colorspace(m_option_t *prop, int action,
return M_PROPERTY_UNAVAILABLE;
char * const names[] = {"BT.601 (SD)", "BT.709 (HD)", "SMPTE-240M"};
if (colorspace < 0 || colorspace >= sizeof(names) / sizeof(names[0]))
*(char **)arg = strdup("Unknown");
*(char **)arg = talloc_strdup(NULL, mp_gtext("unknown"));
else
*(char**)arg = strdup(names[colorspace]);
*(char**)arg = talloc_strdup(NULL, names[colorspace]);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
@ -1327,7 +1318,8 @@ static int mp_property_framedropping(m_option_t *prop, int action,
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **) arg = strdup(frame_dropping == 1 ? mp_gtext("enabled") :
*(char **) arg = talloc_strdup(NULL,
frame_dropping == 1 ? mp_gtext("enabled") :
(frame_dropping == 2 ? mp_gtext("hard") :
mp_gtext("disabled")));
return M_PROPERTY_OK;
@ -1414,20 +1406,19 @@ static int mp_property_video_format(m_option_t *prop, int action,
return M_PROPERTY_ERROR;
switch(mpctx->sh_video->format) {
case 0x10000001:
meta = strdup ("mpeg1"); break;
meta = talloc_strdup(NULL, "mpeg1"); break;
case 0x10000002:
meta = strdup ("mpeg2"); break;
meta = talloc_strdup(NULL, "mpeg2"); break;
case 0x10000004:
meta = strdup ("mpeg4"); break;
meta = talloc_strdup(NULL, "mpeg4"); break;
case 0x10000005:
meta = strdup ("h264"); break;
meta = talloc_strdup(NULL, "h264"); break;
default:
if(mpctx->sh_video->format >= 0x20202020) {
meta = malloc(5);
sprintf (meta, "%.4s", (char *) &mpctx->sh_video->format);
meta = talloc_asprintf(NULL, "%.4s",
(char *) &mpctx->sh_video->format);
} else {
meta = malloc(20);
sprintf (meta, "0x%08X", mpctx->sh_video->format);
meta = talloc_asprintf(NULL, "0x%08X", mpctx->sh_video->format);
}
}
*(char**)arg = meta;
@ -1537,8 +1528,6 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **) arg = malloc(64);
(*(char **) arg)[63] = 0;
char *sub_name = NULL;
if (mpctx->subdata)
sub_name = mpctx->subdata->filename;
@ -1551,7 +1540,7 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
if (sub_name) {
const char *tmp = mp_basename(sub_name);
snprintf(*(char **) arg, 63, "(%d) %s%s",
*(char **) arg = talloc_asprintf(NULL, "(%d) %s%s",
mpctx->set_of_sub_pos + 1,
strlen(tmp) < 20 ? "" : "...",
strlen(tmp) < 20 ? tmp : tmp + strlen(tmp) - 19);
@ -1562,7 +1551,8 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
if (vo_spudec && opts->sub_id >= 0) {
unsigned char lang[3];
if (mp_dvdnav_lang_from_sid(mpctx->stream, opts->sub_id, lang)) {
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
opts->sub_id, lang);
return M_PROPERTY_OK;
}
}
@ -1576,14 +1566,15 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
&& d_sub->sh && opts->sub_id >= 0) {
const char* lang = ((sh_sub_t*)d_sub->sh)->lang;
if (!lang) lang = mp_gtext("unknown");
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
opts->sub_id, lang);
return M_PROPERTY_OK;
}
if (vo_vobsub && vobsub_id >= 0) {
const char *language = mp_gtext("unknown");
language = vobsub_get_id(vo_vobsub, (unsigned int) vobsub_id);
snprintf(*(char **) arg, 63, "(%d) %s",
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
vobsub_id, language ? language : mp_gtext("unknown"));
return M_PROPERTY_OK;
}
@ -1595,16 +1586,17 @@ static int mp_property_sub(m_option_t *prop, int action, void *arg,
lang[0] = code >> 8;
lang[1] = code;
lang[2] = 0;
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id, lang);
*(char **) arg = talloc_asprintf(NULL, "(%d) %s",
opts->sub_id, lang);
return M_PROPERTY_OK;
}
#endif
if (opts->sub_id >= 0) {
snprintf(*(char **) arg, 63, "(%d) %s", opts->sub_id,
*(char **) arg = talloc_asprintf(NULL, "(%d) %s", opts->sub_id,
mp_gtext("unknown"));
return M_PROPERTY_OK;
}
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
return M_PROPERTY_OK;
case M_PROPERTY_SET:
@ -1737,22 +1729,21 @@ static int mp_property_sub_source(m_option_t *prop, int action, void *arg,
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **) arg = malloc(64);
(*(char **) arg)[63] = 0;
switch (sub_source(mpctx))
{
char *sourcename;
switch (sub_source(mpctx)) {
case SUB_SOURCE_SUBS:
snprintf(*(char **) arg, 63, mp_gtext("file"));
sourcename = mp_gtext("file");
break;
case SUB_SOURCE_VOBSUB:
snprintf(*(char **) arg, 63, mp_gtext("vobsub"));
sourcename = mp_gtext("vobsub");
break;
case SUB_SOURCE_DEMUX:
snprintf(*(char **) arg, 63, mp_gtext("embedded"));
sourcename = mp_gtext("embedded");
break;
default:
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
sourcename = mp_gtext("disabled");
}
*(char **)arg = talloc_strdup(NULL, sourcename);
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
@ -1840,9 +1831,7 @@ static int mp_property_sub_by_type(m_option_t *prop, int action, void *arg,
return M_PROPERTY_ERROR;
if (is_cur_source)
return mp_property_sub(prop, M_PROPERTY_PRINT, arg, mpctx);
*(char **) arg = malloc(64);
(*(char **) arg)[63] = 0;
snprintf(*(char **) arg, 63, mp_gtext("disabled"));
*(char **) arg = talloc_strdup(NULL, mp_gtext("disabled"));
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
@ -1923,7 +1912,7 @@ static int mp_property_sub_alignment(m_option_t *prop, int action,
if (!arg)
return M_PROPERTY_ERROR;
M_PROPERTY_CLAMP(prop, sub_alignment);
*(char **) arg = strdup(mp_gtext(name[sub_alignment]));
*(char **) arg = talloc_strdup(NULL, mp_gtext(name[sub_alignment]));
return M_PROPERTY_OK;
case M_PROPERTY_SET:
if (!arg)
@ -2482,7 +2471,7 @@ static int show_property_osd(MPContext *mpctx, const char *pname)
int index = p - property_osd_display;
set_osd_tmsg(p->osd_id >= 0 ? p->osd_id : OSD_MSG_PROPERTY + index,
1, opts->osd_duration, p->osd_msg, val);
free(val);
talloc_free(val);
}
}
return 0;
@ -2822,7 +2811,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
}
mp_msg(MSGT_GLOBAL, MSGL_INFO, "ANS_%s=%s\n",
cmd->args[0].v.s, tmp);
free(tmp);
talloc_free(tmp);
}
break;

View File

@ -27,6 +27,7 @@
#include "config.h"
#include "talloc.h"
#include "m_struct.h"
#include "m_option.h"
#include "input/input.h"
@ -111,7 +112,9 @@ static int fill_menu (menu_t* menu)
if ((e = calloc (1, sizeof (list_entry_t))) != NULL) {
e->cid = cid + 1;
e->p.next = NULL;
e->p.txt = demuxer_chapter_display_name(demuxer, cid);
char *str = demuxer_chapter_display_name(demuxer, cid);
e->p.txt = strdup(str);
talloc_free(str);
start_time = demuxer_chapter_time(demuxer, cid, NULL);
if (start_time >= 0) {
char timestr[13];

View File

@ -1468,18 +1468,16 @@ char *demuxer_chapter_display_name(demuxer_t *demuxer, int chapter)
{
char *chapter_name = demuxer_chapter_name(demuxer, chapter);
if (chapter_name) {
char *tmp = malloc(strlen(chapter_name) + 14);
snprintf(tmp, 63, "(%d) %s", chapter + 1, chapter_name);
char *tmp = talloc_asprintf(NULL, "(%d) %s", chapter + 1, chapter_name);
free(chapter_name);
return tmp;
} else {
int chapter_num = demuxer_chapter_count(demuxer);
char tmp[30];
if (chapter_num <= 0)
sprintf(tmp, "(%d)", chapter + 1);
return talloc_asprintf(NULL, "(%d)", chapter + 1);
else
sprintf(tmp, "(%d) of %d", chapter + 1, chapter_num);
return strdup(tmp);
return talloc_asprintf(NULL, "(%d) of %d", chapter + 1,
chapter_num);
}
}

View File

@ -29,8 +29,8 @@
#include <inttypes.h>
#include <unistd.h>
#include "talloc.h"
#include "m_option.h"
//#include "m_config.h"
#include "mp_msg.h"
#include "stream/url.h"
#include "libavutil/avstring.h"
@ -64,34 +64,6 @@ static void copy_opt(const m_option_t *opt, void *dst, const void *src)
memcpy(dst, src, opt->type->size);
}
// Helper for the print funcs (from man printf)
static char *dup_printf(const char *fmt, ...)
{
/* Guess we need no more than 50 bytes. */
int n, size = 50;
char *p;
va_list ap;
if ((p = malloc(size)) == NULL)
return NULL;
while (1) {
/* Try to print in the allocated space. */
va_start(ap, fmt);
n = vsnprintf(p, size, fmt, ap);
va_end(ap);
/* If that worked, return the string. */
if (n > -1 && n < size)
return p;
/* Else try again with more space. */
if (n > -1) /* glibc 2.1 */
size = n + 1; /* precisely what is needed */
else /* glibc 2.0 */
size *= 2; /* twice the old size */
if ((p = realloc(p, size)) == NULL)
return NULL;
}
}
// Flag
#define VAL(x) (*(int *)(x))
@ -144,9 +116,9 @@ static int parse_flag(const m_option_t *opt, const char *name,
static char *print_flag(const m_option_t *opt, const void *val)
{
if (VAL(val) == opt->min)
return strdup("no");
return talloc_strdup(NULL, "no");
else
return strdup("yes");
return talloc_strdup(NULL, "yes");
}
const m_option_type_t m_option_type_flag = {
@ -210,8 +182,8 @@ static int parse_int(const m_option_t *opt, const char *name,
static char *print_int(const m_option_t *opt, const void *val)
{
if (opt->type->size == sizeof(int64_t))
return dup_printf("%"PRId64, *(const int64_t *)val);
return dup_printf("%d", VAL(val));
return talloc_asprintf(NULL, "%"PRId64, *(const int64_t *)val);
return talloc_asprintf(NULL, "%d", VAL(val));
}
const m_option_type_t m_option_type_int = {
@ -317,7 +289,7 @@ static char *print_choice(const m_option_t *opt, const void *val)
struct m_opt_choice_alternatives *alt;
for (alt = opt->priv; alt->name; alt++)
if (alt->value == v)
return strdup(alt->name);
return talloc_strdup(NULL, alt->name);
abort();
}
@ -395,7 +367,7 @@ static int parse_double(const m_option_t *opt, const char *name,
static char *print_double(const m_option_t *opt, const void *val)
{
opt = NULL;
return dup_printf("%f", VAL(val));
return talloc_asprintf(NULL, "%f", VAL(val));
}
const m_option_type_t m_option_type_double = {
@ -427,7 +399,7 @@ static int parse_float(const m_option_t *opt, const char *name,
static char *print_float(const m_option_t *opt, const void *val)
{
opt = NULL;
return dup_printf("%f", VAL(val));
return talloc_asprintf(NULL, "%f", VAL(val));
}
const m_option_type_t m_option_type_float = {
@ -485,7 +457,7 @@ static int parse_position(const m_option_t *opt, const char *name,
static char *print_position(const m_option_t *opt, const void *val)
{
return dup_printf("%"PRId64, (int64_t)VAL(val));
return talloc_asprintf(NULL, "%"PRId64, (int64_t)VAL(val));
}
const m_option_type_t m_option_type_position = {
@ -538,7 +510,7 @@ static int parse_str(const m_option_t *opt, const char *name,
static char *print_str(const m_option_t *opt, const void *val)
{
return (val && VAL(val) && strlen(VAL(val)) > 0) ? strdup(VAL(val)) : NULL;
return (val && VAL(val)) ? talloc_strdup(NULL, VAL(val)) : NULL;
}
static void copy_str(const m_option_t *opt, void *dst, const void *src)
@ -825,23 +797,17 @@ static void copy_str_list(const m_option_t *opt, void *dst, const void *src)
static char *print_str_list(const m_option_t *opt, const void *src)
{
char **lst = NULL;
char *ret = NULL, *last = NULL;
int i;
char *ret = NULL;
if (!(src && VAL(src)))
return NULL;
lst = VAL(src);
for (i = 0; lst[i]; i++) {
if (last) {
ret = dup_printf("%s,%s", last, lst[i]);
free(last);
} else
ret = strdup(lst[i]);
last = ret;
for (int i = 0; lst[i]; i++) {
if (ret)
ret = talloc_strdup_append_buffer(ret, ",");
ret = talloc_strdup_append_buffer(ret, lst[i]);
}
if (last && last != ret)
free(last);
return ret;
}

View File

@ -460,7 +460,7 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
if (opt->type->print)
return opt->type->print(opt, val_ptr);
else
return (char *)-1;
return NULL;
}
// Helper around \ref m_option_type::copy.

View File

@ -27,6 +27,7 @@
#include <inttypes.h>
#include <unistd.h>
#include "talloc.h"
#include "m_option.h"
#include "m_property.h"
#include "mp_msg.h"
@ -69,7 +70,6 @@ int m_property_do(const m_option_t *prop_list, const char *name,
{
const m_option_t *opt;
void *val;
char *str;
int r;
switch (action) {
@ -92,10 +92,10 @@ int m_property_do(const m_option_t *prop_list, const char *name,
}
if (!arg)
return M_PROPERTY_ERROR;
str = m_option_print(opt, val);
char *str = m_option_print(opt, val);
free(val);
*(char **)arg = str == (char *)-1 ? NULL : str;
return str != (char *)-1;
*(char **)arg = str;
return str != NULL;
case M_PROPERTY_PARSE:
// try the property own parsing func
if ((r = do_action(prop_list, name, M_PROPERTY_PARSE, arg, ctx)) !=
@ -200,7 +200,7 @@ char *m_properties_expand_string(const m_option_t *prop_list, char *str,
memcpy(ret + pos, p, l);
pos += l;
if (fr)
free(p), fr = 0;
talloc_free(p), fr = 0;
}
ret[pos] = 0;
@ -290,7 +290,7 @@ int m_property_flag_ro(const m_option_t *prop, int action,
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = strdup((var > prop->min) ?
*(char **)arg = talloc_strdup(NULL, (var > prop->min) ?
mp_gtext("enabled") : mp_gtext("disabled"));
return 1;
}
@ -323,8 +323,7 @@ int m_property_float_ro(const m_option_t *prop, int action,
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = malloc(20);
sprintf(*(char **)arg, "%.2f", var);
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@ -357,8 +356,7 @@ int m_property_delay(const m_option_t *prop, int action,
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = malloc(20);
sprintf(*(char **)arg, "%d ms", ROUND((*var) * 1000));
*(char **)arg = talloc_asprintf(NULL, "%d ms", ROUND((*var) * 1000));
return 1;
default:
return m_property_float_range(prop, action, arg, var);
@ -377,8 +375,7 @@ int m_property_double_ro(const m_option_t *prop, int action,
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = malloc(20);
sprintf(*(char **)arg, "%.2f", var);
*(char **)arg = talloc_asprintf(NULL, "%.2f", var);
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@ -397,13 +394,12 @@ int m_property_time_ro(const m_option_t *prop, int action,
s -= h * 3600;
m = s / 60;
s -= m * 60;
*(char **) arg = malloc(20);
if (h > 0)
sprintf(*(char **) arg, "%d:%02d:%02d", h, m, s);
*(char **)arg = talloc_asprintf(NULL, "%d:%02d:%02d", h, m, s);
else if (m > 0)
sprintf(*(char **) arg, "%d:%02d", m, s);
*(char **)arg = talloc_asprintf(NULL, "%d:%02d", m, s);
else
sprintf(*(char **) arg, "%d", s);
*(char **)arg = talloc_asprintf(NULL, "%d", s);
return M_PROPERTY_OK;
}
}
@ -422,7 +418,7 @@ int m_property_string_ro(const m_option_t *prop, int action, void *arg,
case M_PROPERTY_PRINT:
if (!arg)
return 0;
*(char **)arg = str ? strdup(str) : NULL;
*(char **)arg = talloc_strdup(NULL, str);
return 1;
}
return M_PROPERTY_NOT_IMPLEMENTED;
@ -434,8 +430,7 @@ int m_property_bitrate(const m_option_t *prop, int action, void *arg, int rate)
case M_PROPERTY_PRINT:
if (!arg)
return M_PROPERTY_ERROR;
*(char **)arg = malloc(16);
sprintf(*(char **)arg, "%d kbps", rate * 8 / 1000);
*(char **)arg = talloc_asprintf(NULL, "%d kbps", rate * 8 / 1000);
return M_PROPERTY_OK;
}
return m_property_int_ro(prop, action, arg, rate);

View File

@ -3308,7 +3308,7 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
{
if (!mpctx->chapters || !mpctx->sh_video)
return demuxer_chapter_display_name(mpctx->demuxer, chapter);
return strdup(mpctx->chapters[chapter].name);
return talloc_strdup(NULL, mpctx->chapters[chapter].name);
}
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,