Mercurial > libavformat.hg
comparison dsicin.c @ 5672:6ba79753bdd4 libavformat
Fix memory leak for truncated frames
author | vitor |
---|---|
date | Fri, 19 Feb 2010 20:19:41 +0000 |
parents | 49c1d3b27727 |
children | 536e5527c1e0 |
comparison
equal
deleted
inserted
replaced
5671:4a65c87ff3fd | 5672:6ba79753bdd4 |
---|---|
160 { | 160 { |
161 CinDemuxContext *cin = s->priv_data; | 161 CinDemuxContext *cin = s->priv_data; |
162 ByteIOContext *pb = s->pb; | 162 ByteIOContext *pb = s->pb; |
163 CinFrameHeader *hdr = &cin->frame_header; | 163 CinFrameHeader *hdr = &cin->frame_header; |
164 int rc, palette_type, pkt_size; | 164 int rc, palette_type, pkt_size; |
165 int ret; | |
165 | 166 |
166 if (cin->audio_buffer_size == 0) { | 167 if (cin->audio_buffer_size == 0) { |
167 rc = cin_read_frame_header(cin, pb); | 168 rc = cin_read_frame_header(cin, pb); |
168 if (rc) | 169 if (rc) |
169 return rc; | 170 return rc; |
176 } | 177 } |
177 | 178 |
178 /* palette and video packet */ | 179 /* palette and video packet */ |
179 pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size; | 180 pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size; |
180 | 181 |
181 if (av_new_packet(pkt, 4 + pkt_size)) | 182 ret = av_new_packet(pkt, 4 + pkt_size); |
182 return AVERROR(ENOMEM); | 183 if (ret < 0) |
184 return ret; | |
183 | 185 |
184 pkt->stream_index = cin->video_stream_index; | 186 pkt->stream_index = cin->video_stream_index; |
185 pkt->pts = cin->video_stream_pts++; | 187 pkt->pts = cin->video_stream_pts++; |
186 | 188 |
187 pkt->data[0] = palette_type; | 189 pkt->data[0] = palette_type; |
188 pkt->data[1] = hdr->pal_colors_count & 0xFF; | 190 pkt->data[1] = hdr->pal_colors_count & 0xFF; |
189 pkt->data[2] = hdr->pal_colors_count >> 8; | 191 pkt->data[2] = hdr->pal_colors_count >> 8; |
190 pkt->data[3] = hdr->video_frame_type; | 192 pkt->data[3] = hdr->video_frame_type; |
191 | 193 |
192 if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size) | 194 ret = get_buffer(pb, &pkt->data[4], pkt_size); |
193 return AVERROR(EIO); | 195 if (ret < 0) { |
196 av_free_packet(pkt); | |
197 return ret; | |
198 } | |
199 if (ret < pkt_size) | |
200 av_shrink_packet(pkt, 4 + ret); | |
194 | 201 |
195 /* sound buffer will be processed on next read_packet() call */ | 202 /* sound buffer will be processed on next read_packet() call */ |
196 cin->audio_buffer_size = hdr->audio_frame_size; | 203 cin->audio_buffer_size = hdr->audio_frame_size; |
197 return 0; | 204 return 0; |
198 } | 205 } |
199 | 206 |
200 /* audio packet */ | 207 /* audio packet */ |
201 if (av_new_packet(pkt, cin->audio_buffer_size)) | 208 ret = av_get_packet(pb, pkt, cin->audio_buffer_size); |
202 return AVERROR(ENOMEM); | 209 if (ret < 0) |
210 return ret; | |
203 | 211 |
204 pkt->stream_index = cin->audio_stream_index; | 212 pkt->stream_index = cin->audio_stream_index; |
205 pkt->pts = cin->audio_stream_pts; | 213 pkt->pts = cin->audio_stream_pts; |
206 cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; | 214 cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; |
207 | |
208 if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size) | |
209 return AVERROR(EIO); | |
210 | |
211 cin->audio_buffer_size = 0; | 215 cin->audio_buffer_size = 0; |
212 return 0; | 216 return 0; |
213 } | 217 } |
214 | 218 |
215 AVInputFormat dsicin_demuxer = { | 219 AVInputFormat dsicin_demuxer = { |