avformat/segment: Use av_freep() avoid leaving stale pointers in memory

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/101/head
Michael Niedermayer 10 years ago
parent 1515bfb313
commit 68fa549230
  1. 14
      libavformat/segment.c

@ -343,7 +343,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last)
if (seg->list_size && seg->segment_count >= seg->list_size) { if (seg->list_size && seg->segment_count >= seg->list_size) {
entry = seg->segment_list_entries; entry = seg->segment_list_entries;
seg->segment_list_entries = seg->segment_list_entries->next; seg->segment_list_entries = seg->segment_list_entries->next;
av_free(entry->filename); av_freep(&entry->filename);
av_freep(&entry); av_freep(&entry);
} }
@ -501,10 +501,10 @@ static int open_null_ctx(AVIOContext **ctx)
return 0; return 0;
} }
static void close_null_ctx(AVIOContext *pb) static void close_null_ctxp(AVIOContext **pb)
{ {
av_free(pb->buffer); av_freep(&(*pb)->buffer);
av_free(pb); av_freep(pb);
} }
static int select_reference_stream(AVFormatContext *s) static int select_reference_stream(AVFormatContext *s)
@ -687,7 +687,7 @@ static int seg_write_header(AVFormatContext *s)
s->avoid_negative_ts = 1; s->avoid_negative_ts = 1;
if (!seg->write_header_trailer) { if (!seg->write_header_trailer) {
close_null_ctx(oc->pb); close_null_ctxp(&oc->pb);
if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
&s->interrupt_callback, NULL)) < 0) &s->interrupt_callback, NULL)) < 0)
goto fail; goto fail;
@ -820,7 +820,7 @@ static int seg_write_trailer(struct AVFormatContext *s)
goto fail; goto fail;
open_null_ctx(&oc->pb); open_null_ctx(&oc->pb);
ret = av_write_trailer(oc); ret = av_write_trailer(oc);
close_null_ctx(oc->pb); close_null_ctxp(&oc->pb);
} else { } else {
ret = segment_end(s, 1, 1); ret = segment_end(s, 1, 1);
} }
@ -836,7 +836,7 @@ fail:
cur = seg->segment_list_entries; cur = seg->segment_list_entries;
while (cur) { while (cur) {
next = cur->next; next = cur->next;
av_free(cur->filename); av_freep(&cur->filename);
av_free(cur); av_free(cur);
cur = next; cur = next;
} }

Loading…
Cancel
Save