diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-11-12 17:28:53 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-11-12 17:54:52 +0100 |
commit | 39dfe6801a3f67c2964a829b65e8e38e3cb22217 (patch) | |
tree | 3fea5b7658a86cf7ec0d600b0ba737f6fa88c17a | |
parent | e74e14608fa331b89efefa8e3ecdb1077df5922b (diff) | |
download | ffmpeg-39dfe6801a3f67c2964a829b65e8e38e3cb22217.tar.gz |
avcodec/dvbsubdec: Cleanup on *malloc failure
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavcodec/dvbsubdec.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index 738bd5a43f..e0d678e210 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -762,6 +762,7 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou uint32_t *clut_table; int i; int offset_x=0, offset_y=0; + int ret = 0; if (display_def) { @@ -790,8 +791,10 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou if (sub->num_rects > 0) { sub->rects = av_mallocz_array(sizeof(*sub->rects), sub->num_rects); - if (!sub->rects) - return AVERROR(ENOMEM); + if (!sub->rects) { + ret = AVERROR(ENOMEM); + goto fail; + } for(i=0; i<sub->num_rects; i++) sub->rects[i] = av_mallocz(sizeof(*sub->rects[i])); @@ -836,16 +839,15 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou rect->pict.data[1] = av_mallocz(AVPALETTE_SIZE); if (!rect->pict.data[1]) { - av_freep(&sub->rects); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto fail; } memcpy(rect->pict.data[1], clut_table, (1 << region->depth) * sizeof(uint32_t)); rect->pict.data[0] = av_malloc(region->buf_size); if (!rect->pict.data[0]) { - av_freep(&rect->pict.data[1]); - av_freep(&sub->rects); - return AVERROR(ENOMEM); + ret = AVERROR(ENOMEM); + goto fail; } memcpy(rect->pict.data[0], region->pbuf, region->buf_size); @@ -855,6 +857,20 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou } return 0; +fail: + if (sub->rects) { + for(i=0; i<sub->num_rects; i++) { + rect = sub->rects[i]; + if (rect) { + av_freep(&rect->pict.data[0]); + av_freep(&rect->pict.data[1]); + } + av_freep(&sub->rects[i]); + } + av_freep(&sub->rects); + } + sub->num_rects = 0; + return ret; } static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, |