avformat/flac_picture: Avoid allocation of AVIOContext
Put an AVIOContext whose lifetime doesn't extend beyond the function where it is allocated on the stack instead of allocating and freeing it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
committed by
Paul B Mahol
parent
4cb124a800
commit
69dd8d3a2a
@@ -26,6 +26,7 @@
|
|||||||
#include "flac_picture.h"
|
#include "flac_picture.h"
|
||||||
#include "id3v2.h"
|
#include "id3v2.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "avio_internal.h"
|
||||||
|
|
||||||
int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
|
int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
|
||||||
{
|
{
|
||||||
@@ -33,15 +34,13 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
|
|||||||
enum AVCodecID id = AV_CODEC_ID_NONE;
|
enum AVCodecID id = AV_CODEC_ID_NONE;
|
||||||
AVBufferRef *data = NULL;
|
AVBufferRef *data = NULL;
|
||||||
uint8_t mimetype[64], *desc = NULL;
|
uint8_t mimetype[64], *desc = NULL;
|
||||||
AVIOContext *pb = NULL;
|
AVIOContext pb0, *pb = &pb0;
|
||||||
AVStream *st;
|
AVStream *st;
|
||||||
int width, height, ret = 0;
|
int width, height, ret = 0;
|
||||||
int len;
|
int len;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
|
||||||
pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL);
|
ffio_init_context(pb, buf, buf_size, 0, NULL, NULL, NULL, NULL);
|
||||||
if (!pb)
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
|
|
||||||
/* read the picture type */
|
/* read the picture type */
|
||||||
type = avio_rb32(pb);
|
type = avio_rb32(pb);
|
||||||
@@ -145,14 +144,11 @@ int ff_flac_parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
|
|||||||
if (desc)
|
if (desc)
|
||||||
av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
|
av_dict_set(&st->metadata, "title", desc, AV_DICT_DONT_STRDUP_VAL);
|
||||||
|
|
||||||
avio_context_free(&pb);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
av_buffer_unref(&data);
|
av_buffer_unref(&data);
|
||||||
av_freep(&desc);
|
av_freep(&desc);
|
||||||
avio_context_free(&pb);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user