comparison libmpdemux/demuxer.c @ 18708:9e2b300db17b

Change free_sh_audio() to take demuxer and stream id as parameters (same as new_sh_audio()) instead of sh_audio_t *, use those to remove the pointer from demuxer->a_streams[] before freeing it. Some demuxers use free_sh_audio() to undo the creation of an already-allocated audio stream in case of error. These uses were unsafe since free_sh_audio() freed the data structure but left the pointer in demuxer->a_streams[], leading to double free later in free_demuxer() (and perhaps use of the freed stream before that, I didn't check).
author uau
date Wed, 14 Jun 2006 14:05:59 +0000
parents e3379df74bcd
children 0b53e6d1b27f
comparison
equal deleted inserted replaced
18707:60a60dbf7a88 18708:9e2b300db17b
227 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", id); 227 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_ID=%d\n", id);
228 } 228 }
229 return demuxer->a_streams[id]; 229 return demuxer->a_streams[id];
230 } 230 }
231 231
232 void free_sh_audio(sh_audio_t* sh){ 232 void free_sh_audio(demuxer_t *demuxer, int id) {
233 sh_audio_t *sh = demuxer->a_streams[id];
234 demuxer->a_streams[id] = NULL;
233 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"DEMUXER: freeing sh_audio at %p\n",sh); 235 mp_msg(MSGT_DEMUXER,MSGL_DBG2,"DEMUXER: freeing sh_audio at %p\n",sh);
234 if(sh->wf) free(sh->wf); 236 if(sh->wf) free(sh->wf);
235 free(sh); 237 free(sh);
236 } 238 }
237 239
268 // Very ugly hack to make it behave like old implementation 270 // Very ugly hack to make it behave like old implementation
269 if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS) 271 if (demuxer->desc->type == DEMUXER_TYPE_DEMUXERS)
270 goto skip_streamfree; 272 goto skip_streamfree;
271 // free streams: 273 // free streams:
272 for(i = 0; i < MAX_A_STREAMS; i++) 274 for(i = 0; i < MAX_A_STREAMS; i++)
273 if(demuxer->a_streams[i]) free_sh_audio(demuxer->a_streams[i]); 275 if(demuxer->a_streams[i]) free_sh_audio(demuxer, i);
274 for(i = 0; i < MAX_V_STREAMS; i++) 276 for(i = 0; i < MAX_V_STREAMS; i++)
275 if(demuxer->v_streams[i]) free_sh_video(demuxer->v_streams[i]); 277 if(demuxer->v_streams[i]) free_sh_video(demuxer->v_streams[i]);
276 //if(sh_audio) free_sh_audio(sh_audio);
277 //if(sh_video) free_sh_video(sh_video);
278 // free demuxers: 278 // free demuxers:
279 free_demuxer_stream(demuxer->audio); 279 free_demuxer_stream(demuxer->audio);
280 free_demuxer_stream(demuxer->video); 280 free_demuxer_stream(demuxer->video);
281 free_demuxer_stream(demuxer->sub); 281 free_demuxer_stream(demuxer->sub);
282 skip_streamfree: 282 skip_streamfree: