aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/opt.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2014-12-17 14:53:45 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2014-12-18 23:27:14 +0100
commitb1306823d0b3ae998c8e10ad832004eb13bdd93e (patch)
tree2e7642dc896d7f19682f50b913ab5b5be57b83ac /libavutil/opt.c
parent9745f19ffc9031ce480e43d7cf1053b58100d70f (diff)
downloadffmpeg-b1306823d0b3ae998c8e10ad832004eb13bdd93e.tar.gz
check memory errors from av_strdup()
Diffstat (limited to 'libavutil/opt.c')
-rw-r--r--libavutil/opt.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 28adef6877..6785a08741 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -138,7 +138,7 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d
{
av_freep(dst);
*dst = av_strdup(val);
- return 0;
+ return *dst ? 0 : AVERROR(ENOMEM);
}
#define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
@@ -350,7 +350,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
*out_val = av_strdup(*(uint8_t**)dst);
else
*out_val = av_strdup("");
- return 0;
+ return *out_val ? 0 : AVERROR(ENOMEM);
case AV_OPT_TYPE_BINARY:
len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
if ((uint64_t)len*2 + 1 > INT_MAX)
@@ -368,7 +368,7 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
if (ret >= sizeof(buf))
return AVERROR(EINVAL);
*out_val = av_strdup(buf);
- return 0;
+ return *out_val ? 0 : AVERROR(ENOMEM);
}
static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
@@ -828,6 +828,8 @@ int main(void)
test_ctx.class = &test_class;
av_opt_set_defaults(&test_ctx);
test_ctx.string = av_strdup("default");
+ if (!test_ctx.string)
+ return AVERROR(ENOMEM);
av_log_set_level(AV_LOG_DEBUG);