comparison a64.c @ 6449:3a28e6827095 libavformat

Solving memory leak and initialization problem with prev_pkt / pkt.
author bindhammer
date Tue, 31 Aug 2010 07:15:11 +0000
parents d2d2972c9715
children
comparison
equal deleted inserted replaced
6448:4775a49a6045 6449:3a28e6827095
123 for(j = 0; j < frame_size; j++) put_byte(s->pb, 0); 123 for(j = 0; j < frame_size; j++) put_byte(s->pb, 0);
124 } 124 }
125 } 125 }
126 /* backup current packet for next turn */ 126 /* backup current packet for next turn */
127 if(pkt->data) { 127 if(pkt->data) {
128 av_new_packet(&c->prev_pkt, pkt->size); 128 /* no backup packet yet? create one! */
129 memcpy(c->prev_pkt.data, pkt->data, pkt->size); 129 if(!c->prev_pkt.data) av_new_packet(&c->prev_pkt, pkt->size);
130 /* we have a packet and data is big enough, reuse it */
131 if(c->prev_pkt.data && c->prev_pkt.size >= pkt->size) {
132 memcpy(c->prev_pkt.data, pkt->data, pkt->size);
133 c->prev_pkt.size = pkt->size;
134 } else {
135 av_log(avctx, AV_LOG_ERROR, "Too less memory for prev_pkt.\n");
136 return AVERROR(ENOMEM);
137 }
130 } 138 }
131 c->prev_frame_count = frame_count; 139 c->prev_frame_count = frame_count;
132 break; 140 break;
133 } 141 }
134 default: 142 default:
143 } 151 }
144 152
145 static int a64_write_trailer(struct AVFormatContext *s) 153 static int a64_write_trailer(struct AVFormatContext *s)
146 { 154 {
147 A64MuxerContext *c = s->priv_data; 155 A64MuxerContext *c = s->priv_data;
148 AVPacket pkt; 156 AVPacket pkt = {0};
149 /* need to flush last packet? */ 157 /* need to flush last packet? */
150 if(c->interleaved) a64_write_packet(s, &pkt); 158 if(c->interleaved) a64_write_packet(s, &pkt);
159 /* discard backed up packet */
160 if(c->prev_pkt.data) av_destruct_packet(&c->prev_pkt);
151 return 0; 161 return 0;
152 } 162 }
153 163
154 AVOutputFormat a64_muxer = { 164 AVOutputFormat a64_muxer = {
155 .name = "a64", 165 .name = "a64",