decoder/mad: use std::unique_ptr

This commit is contained in:
Max Kellermann 2017-12-20 15:32:10 +01:00
parent 9f33c6fe03
commit 499e053d58

View File

@ -321,7 +321,7 @@ inline void
MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag) MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
{ {
#ifdef ENABLE_ID3TAG #ifdef ENABLE_ID3TAG
id3_byte_t *allocated = nullptr; std::unique_ptr<id3_byte_t[]> allocated;
const id3_length_t count = stream.bufend - stream.this_frame; const id3_length_t count = stream.bufend - stream.this_frame;
@ -330,25 +330,22 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_data = stream.this_frame; id3_data = stream.this_frame;
mad_stream_skip(&(stream), tagsize); mad_stream_skip(&(stream), tagsize);
} else { } else {
allocated = new id3_byte_t[tagsize]; allocated.reset(new id3_byte_t[tagsize]);
memcpy(allocated, stream.this_frame, count); memcpy(allocated.get(), stream.this_frame, count);
mad_stream_skip(&(stream), count); mad_stream_skip(&(stream), count);
if (!decoder_read_full(client, input_stream, if (!decoder_read_full(client, input_stream,
allocated + count, tagsize - count)) { allocated.get() + count, tagsize - count)) {
LogDebug(mad_domain, "error parsing ID3 tag"); LogDebug(mad_domain, "error parsing ID3 tag");
delete[] allocated;
return; return;
} }
id3_data = allocated; id3_data = allocated.get();
} }
struct id3_tag *const id3_tag = id3_tag_parse(id3_data, tagsize); struct id3_tag *const id3_tag = id3_tag_parse(id3_data, tagsize);
if (id3_tag == nullptr) { if (id3_tag == nullptr)
delete[] allocated;
return; return;
}
if (mpd_tag) { if (mpd_tag) {
auto tmp_tag = tag_id3_import(id3_tag); auto tmp_tag = tag_id3_import(id3_tag);
@ -371,7 +368,6 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_tag_delete(id3_tag); id3_tag_delete(id3_tag);
delete[] allocated;
#else /* !ENABLE_ID3TAG */ #else /* !ENABLE_ID3TAG */
(void)mpd_tag; (void)mpd_tag;