backport latest ffserver fixes like memory leaks and invalid reads
Patches by Howard Chu, hyc at highlandsun dot com backport r23290-23295 by mstorsjo Originally committed as revision 23382 to svn://svn.ffmpeg.org/ffmpeg/branches/0.6
This commit is contained in:
parent
8f3504c3ca
commit
2a546cecbf
34
ffserver.c
34
ffserver.c
@ -847,6 +847,8 @@ static void close_connection(HTTPContext *c)
|
|||||||
ctx = c->rtp_ctx[i];
|
ctx = c->rtp_ctx[i];
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
av_write_trailer(ctx);
|
av_write_trailer(ctx);
|
||||||
|
av_metadata_free(&ctx->metadata);
|
||||||
|
av_free(ctx->streams[0]);
|
||||||
av_free(ctx);
|
av_free(ctx);
|
||||||
}
|
}
|
||||||
h = c->rtp_handles[i];
|
h = c->rtp_handles[i];
|
||||||
@ -2280,6 +2282,7 @@ static int http_prepare_data(HTTPContext *c)
|
|||||||
http_log("Error writing output header\n");
|
http_log("Error writing output header\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
av_metadata_free(&c->fmt_ctx.metadata);
|
||||||
|
|
||||||
len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);
|
len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer);
|
||||||
c->buffer_ptr = c->pb_buffer;
|
c->buffer_ptr = c->pb_buffer;
|
||||||
@ -2343,7 +2346,7 @@ static int http_prepare_data(HTTPContext *c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i=0;i<c->stream->nb_streams;i++) {
|
for(i=0;i<c->stream->nb_streams;i++) {
|
||||||
if (c->feed_streams[i] == pkt.stream_index) {
|
if (c->stream->feed_streams[i] == pkt.stream_index) {
|
||||||
AVStream *st = c->fmt_in->streams[source_index];
|
AVStream *st = c->fmt_in->streams[source_index];
|
||||||
pkt.stream_index = i;
|
pkt.stream_index = i;
|
||||||
if (pkt.flags & AV_PKT_FLAG_KEY &&
|
if (pkt.flags & AV_PKT_FLAG_KEY &&
|
||||||
@ -2879,7 +2882,7 @@ static int rtsp_parse_request(HTTPContext *c)
|
|||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
p++;
|
p++;
|
||||||
while (*p != '\0') {
|
while (*p != '\0') {
|
||||||
p1 = strchr(p, '\n');
|
p1 = memchr(p, '\n', (char *)c->buffer_ptr - p);
|
||||||
if (!p1)
|
if (!p1)
|
||||||
break;
|
break;
|
||||||
p2 = p1;
|
p2 = p1;
|
||||||
@ -2956,6 +2959,7 @@ static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer,
|
|||||||
}
|
}
|
||||||
*pbuffer = av_mallocz(2048);
|
*pbuffer = av_mallocz(2048);
|
||||||
avf_sdp_create(&avc, 1, *pbuffer, 2048);
|
avf_sdp_create(&avc, 1, *pbuffer, 2048);
|
||||||
|
av_metadata_free(&avc->metadata);
|
||||||
av_free(avc);
|
av_free(avc);
|
||||||
|
|
||||||
return strlen(*pbuffer);
|
return strlen(*pbuffer);
|
||||||
@ -3012,6 +3016,7 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url)
|
|||||||
url_fprintf(c->pb, "Content-Length: %d\r\n", content_length);
|
url_fprintf(c->pb, "Content-Length: %d\r\n", content_length);
|
||||||
url_fprintf(c->pb, "\r\n");
|
url_fprintf(c->pb, "\r\n");
|
||||||
put_buffer(c->pb, content, content_length);
|
put_buffer(c->pb, content, content_length);
|
||||||
|
av_free(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HTTPContext *find_rtp_session(const char *session_id)
|
static HTTPContext *find_rtp_session(const char *session_id)
|
||||||
@ -3378,7 +3383,6 @@ static int rtp_new_av_stream(HTTPContext *c,
|
|||||||
st = av_mallocz(sizeof(AVStream));
|
st = av_mallocz(sizeof(AVStream));
|
||||||
if (!st)
|
if (!st)
|
||||||
goto fail;
|
goto fail;
|
||||||
st->codec= avcodec_alloc_context();
|
|
||||||
ctx->nb_streams = 1;
|
ctx->nb_streams = 1;
|
||||||
ctx->streams[0] = st;
|
ctx->streams[0] = st;
|
||||||
|
|
||||||
@ -3454,16 +3458,28 @@ static int rtp_new_av_stream(HTTPContext *c,
|
|||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
/* ffserver initialization */
|
/* ffserver initialization */
|
||||||
|
|
||||||
static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec)
|
static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int copy)
|
||||||
{
|
{
|
||||||
AVStream *fst;
|
AVStream *fst;
|
||||||
|
|
||||||
fst = av_mallocz(sizeof(AVStream));
|
fst = av_mallocz(sizeof(AVStream));
|
||||||
if (!fst)
|
if (!fst)
|
||||||
return NULL;
|
return NULL;
|
||||||
fst->codec= avcodec_alloc_context();
|
if (copy) {
|
||||||
|
fst->codec= avcodec_alloc_context();
|
||||||
|
memcpy(fst->codec, codec, sizeof(AVCodecContext));
|
||||||
|
if (codec->extradata_size) {
|
||||||
|
fst->codec->extradata = av_malloc(codec->extradata_size);
|
||||||
|
memcpy(fst->codec->extradata, codec->extradata,
|
||||||
|
codec->extradata_size);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* live streams must use the actual feed's codec since it may be
|
||||||
|
* updated later to carry extradata needed by the streams.
|
||||||
|
*/
|
||||||
|
fst->codec = codec;
|
||||||
|
}
|
||||||
fst->priv_data = av_mallocz(sizeof(FeedData));
|
fst->priv_data = av_mallocz(sizeof(FeedData));
|
||||||
memcpy(fst->codec, codec, sizeof(AVCodecContext));
|
|
||||||
fst->index = stream->nb_streams;
|
fst->index = stream->nb_streams;
|
||||||
av_set_pts_info(fst, 33, 1, 90000);
|
av_set_pts_info(fst, 33, 1, 90000);
|
||||||
stream->streams[stream->nb_streams++] = fst;
|
stream->streams[stream->nb_streams++] = fst;
|
||||||
@ -3505,7 +3521,7 @@ static int add_av_stream(FFStream *feed, AVStream *st)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fst = add_av_stream1(feed, av);
|
fst = add_av_stream1(feed, av, 0);
|
||||||
if (!fst)
|
if (!fst)
|
||||||
return -1;
|
return -1;
|
||||||
return feed->nb_streams - 1;
|
return feed->nb_streams - 1;
|
||||||
@ -3616,7 +3632,7 @@ static void build_file_streams(void)
|
|||||||
extract_mpeg4_header(infile);
|
extract_mpeg4_header(infile);
|
||||||
|
|
||||||
for(i=0;i<infile->nb_streams;i++)
|
for(i=0;i<infile->nb_streams;i++)
|
||||||
add_av_stream1(stream, infile->streams[i]->codec);
|
add_av_stream1(stream, infile->streams[i]->codec, 1);
|
||||||
|
|
||||||
av_close_input_file(infile);
|
av_close_input_file(infile);
|
||||||
}
|
}
|
||||||
@ -3683,7 +3699,7 @@ static void build_feed_streams(void)
|
|||||||
ccs = ss->codec;
|
ccs = ss->codec;
|
||||||
#define CHECK_CODEC(x) (ccf->x != ccs->x)
|
#define CHECK_CODEC(x) (ccf->x != ccs->x)
|
||||||
|
|
||||||
if (CHECK_CODEC(codec) || CHECK_CODEC(codec_type)) {
|
if (CHECK_CODEC(codec_id) || CHECK_CODEC(codec_type)) {
|
||||||
http_log("Codecs do not match for stream %d\n", i);
|
http_log("Codecs do not match for stream %d\n", i);
|
||||||
matches = 0;
|
matches = 0;
|
||||||
} else if (CHECK_CODEC(bit_rate) || CHECK_CODEC(flags)) {
|
} else if (CHECK_CODEC(bit_rate) || CHECK_CODEC(flags)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user