mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avformat: Replace ffurl_close() by ffurl_closep() where appropriate
It avoids leaving dangling pointers behind in memory. Also remove redundant checks for whether the URLContext to be closed is already NULL. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
af97c9865f
commit
82bf41f3ab
@ -293,7 +293,7 @@ cond_wakeup_background_fail:
|
||||
cond_wakeup_main_fail:
|
||||
pthread_mutex_destroy(&c->mutex);
|
||||
mutex_fail:
|
||||
ffurl_close(c->inner);
|
||||
ffurl_closep(&c->inner);
|
||||
url_fail:
|
||||
ring_destroy(&c->ring);
|
||||
fifo_fail:
|
||||
@ -317,7 +317,7 @@ static int async_close(URLContext *h)
|
||||
pthread_cond_destroy(&c->cond_wakeup_background);
|
||||
pthread_cond_destroy(&c->cond_wakeup_main);
|
||||
pthread_mutex_destroy(&c->mutex);
|
||||
ffurl_close(c->inner);
|
||||
ffurl_closep(&c->inner);
|
||||
ring_destroy(&c->ring);
|
||||
|
||||
return 0;
|
||||
|
@ -310,7 +310,7 @@ static int cache_close(URLContext *h)
|
||||
av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename);
|
||||
av_freep(&c->filename);
|
||||
}
|
||||
ffurl_close(c->inner);
|
||||
ffurl_closep(&c->inner);
|
||||
av_tree_enumerate(c->root, NULL, NULL, enu_free);
|
||||
av_tree_destroy(c->root);
|
||||
|
||||
|
@ -49,7 +49,7 @@ static av_cold int concat_close(URLContext *h)
|
||||
struct concat_nodes *nodes = data->nodes;
|
||||
|
||||
for (i = 0; i != data->length; i++)
|
||||
err |= ffurl_close(nodes[i].uc);
|
||||
err |= ffurl_closep(&nodes[i].uc);
|
||||
|
||||
av_freep(&data->nodes);
|
||||
|
||||
|
@ -385,8 +385,7 @@ static int crypto_close(URLContext *h)
|
||||
ret = ffurl_write(c->hd, out_buf, BLOCKSIZE);
|
||||
}
|
||||
|
||||
if (c->hd)
|
||||
ffurl_close(c->hd);
|
||||
ffurl_closep(&c->hd);
|
||||
av_freep(&c->aes_decrypt);
|
||||
av_freep(&c->aes_encrypt);
|
||||
av_freep(&c->write_buf);
|
||||
|
@ -68,10 +68,7 @@ static int gopher_connect(URLContext *h, const char *path)
|
||||
static int gopher_close(URLContext *h)
|
||||
{
|
||||
GopherContext *s = h->priv_data;
|
||||
if (s->hd) {
|
||||
ffurl_close(s->hd);
|
||||
s->hd = NULL;
|
||||
}
|
||||
ffurl_closep(&s->hd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ static int hls_close(URLContext *h)
|
||||
|
||||
free_segment_list(s);
|
||||
free_variant_list(s);
|
||||
ffurl_close(s->seg_hd);
|
||||
ffurl_closep(&s->seg_hd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -260,8 +260,7 @@ start:
|
||||
return ret;
|
||||
}
|
||||
if (s->seg_hd) {
|
||||
ffurl_close(s->seg_hd);
|
||||
s->seg_hd = NULL;
|
||||
ffurl_closep(&s->seg_hd);
|
||||
s->cur_seq_no++;
|
||||
}
|
||||
reload_interval = s->n_segments > 0 ?
|
||||
|
@ -75,8 +75,7 @@ static void cat_header(AVBPrint *bp, const char key[], const char value[])
|
||||
static int icecast_close(URLContext *h)
|
||||
{
|
||||
IcecastContext *s = h->priv_data;
|
||||
if (s->hd)
|
||||
ffurl_close(s->hd);
|
||||
ffurl_closep(&s->hd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,7 @@ static int mmsh_close(URLContext *h)
|
||||
{
|
||||
MMSHContext *mmsh = (MMSHContext *)h->priv_data;
|
||||
MMSContext *mms = &mmsh->mms;
|
||||
if (mms->mms_hd)
|
||||
ffurl_closep(&mms->mms_hd);
|
||||
ffurl_closep(&mms->mms_hd);
|
||||
av_freep(&mms->streams);
|
||||
av_freep(&mms->asf_header);
|
||||
return 0;
|
||||
@ -265,7 +264,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim
|
||||
}
|
||||
|
||||
// close the socket and then reopen it for sending the second play request.
|
||||
ffurl_close(mms->mms_hd);
|
||||
ffurl_closep(&mms->mms_hd);
|
||||
memset(headers, 0, sizeof(headers));
|
||||
if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
|
||||
&h->interrupt_callback)) < 0) {
|
||||
|
@ -473,7 +473,7 @@ static int mms_close(URLContext *h)
|
||||
MMSContext *mms = &mmst->mms;
|
||||
if(mms->mms_hd) {
|
||||
send_close_packet(mmst);
|
||||
ffurl_close(mms->mms_hd);
|
||||
ffurl_closep(&mms->mms_hd);
|
||||
}
|
||||
|
||||
/* free all separately allocated pointers in mms */
|
||||
|
@ -240,7 +240,7 @@ static int rtmpe_close(URLContext *h)
|
||||
RTMPEContext *rt = h->priv_data;
|
||||
|
||||
ff_dh_free(rt->dh);
|
||||
ffurl_close(rt->stream);
|
||||
ffurl_closep(&rt->stream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ static int rtmp_http_close(URLContext *h)
|
||||
}
|
||||
|
||||
av_freep(&rt->out_data);
|
||||
ffurl_close(rt->stream);
|
||||
ffurl_closep(&rt->stream);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -2511,7 +2511,7 @@ static int rtmp_close(URLContext *h)
|
||||
|
||||
free_tracked_methods(rt);
|
||||
av_freep(&rt->flv_data);
|
||||
ffurl_close(rt->stream);
|
||||
ffurl_closep(&rt->stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2824,8 +2824,7 @@ reconnect:
|
||||
|
||||
if (rt->do_reconnect) {
|
||||
int i;
|
||||
ffurl_close(rt->stream);
|
||||
rt->stream = NULL;
|
||||
ffurl_closep(&rt->stream);
|
||||
rt->do_reconnect = 0;
|
||||
rt->nb_invokes = 0;
|
||||
for (i = 0; i < 2; i++)
|
||||
|
@ -363,10 +363,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags)
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (s->rtp_hd)
|
||||
ffurl_close(s->rtp_hd);
|
||||
if (s->rtcp_hd)
|
||||
ffurl_close(s->rtcp_hd);
|
||||
ffurl_closep(&s->rtp_hd);
|
||||
ffurl_closep(&s->rtcp_hd);
|
||||
ffurl_closep(&s->fec_hd);
|
||||
av_free(fec_protocol);
|
||||
av_dict_free(&fec_opts);
|
||||
@ -506,8 +504,8 @@ static int rtp_close(URLContext *h)
|
||||
|
||||
ff_ip_reset_filters(&s->filters);
|
||||
|
||||
ffurl_close(s->rtp_hd);
|
||||
ffurl_close(s->rtcp_hd);
|
||||
ffurl_closep(&s->rtp_hd);
|
||||
ffurl_closep(&s->rtcp_hd);
|
||||
ffurl_closep(&s->fec_hd);
|
||||
return 0;
|
||||
}
|
||||
|
@ -763,9 +763,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets)
|
||||
ff_rtp_parse_close(rtsp_st->transport_priv);
|
||||
}
|
||||
rtsp_st->transport_priv = NULL;
|
||||
if (rtsp_st->rtp_handle)
|
||||
ffurl_close(rtsp_st->rtp_handle);
|
||||
rtsp_st->rtp_handle = NULL;
|
||||
ffurl_closep(&rtsp_st->rtp_handle);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1666,9 +1664,10 @@ fail:
|
||||
void ff_rtsp_close_connections(AVFormatContext *s)
|
||||
{
|
||||
RTSPState *rt = s->priv_data;
|
||||
if (rt->rtsp_hd_out != rt->rtsp_hd) ffurl_close(rt->rtsp_hd_out);
|
||||
ffurl_close(rt->rtsp_hd);
|
||||
rt->rtsp_hd = rt->rtsp_hd_out = NULL;
|
||||
if (rt->rtsp_hd_out != rt->rtsp_hd)
|
||||
ffurl_closep(&rt->rtsp_hd_out);
|
||||
rt->rtsp_hd_out = NULL;
|
||||
ffurl_closep(&rt->rtsp_hd);
|
||||
}
|
||||
|
||||
int ff_rtsp_connect(AVFormatContext *s)
|
||||
@ -2496,8 +2495,7 @@ static int rtp_read_header(AVFormatContext *s)
|
||||
break;
|
||||
}
|
||||
getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);
|
||||
ffurl_close(in);
|
||||
in = NULL;
|
||||
ffurl_closep(&in);
|
||||
|
||||
par = avcodec_parameters_alloc();
|
||||
if (!par) {
|
||||
@ -2571,8 +2569,7 @@ fail_nobuf:
|
||||
av_bprint_finalize(&sdp, NULL);
|
||||
fail:
|
||||
avcodec_parameters_free(&par);
|
||||
if (in)
|
||||
ffurl_close(in);
|
||||
ffurl_closep(&in);
|
||||
ff_network_close();
|
||||
return ret;
|
||||
}
|
||||
|
@ -54,8 +54,7 @@ static int sap_read_close(AVFormatContext *s)
|
||||
struct SAPState *sap = s->priv_data;
|
||||
if (sap->sdp_ctx)
|
||||
avformat_close_input(&sap->sdp_ctx);
|
||||
if (sap->ann_fd)
|
||||
ffurl_close(sap->ann_fd);
|
||||
ffurl_closep(&sap->ann_fd);
|
||||
av_freep(&sap->sdp);
|
||||
ff_network_close();
|
||||
return 0;
|
||||
|
@ -60,8 +60,7 @@ static int sap_write_close(AVFormatContext *s)
|
||||
}
|
||||
|
||||
av_freep(&sap->ann);
|
||||
if (sap->ann_fd)
|
||||
ffurl_close(sap->ann_fd);
|
||||
ffurl_closep(&sap->ann_fd);
|
||||
ff_network_close();
|
||||
return 0;
|
||||
}
|
||||
|
@ -99,14 +99,9 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence)
|
||||
if (whence != SEEK_SET)
|
||||
return AVERROR(ENOSYS);
|
||||
if (os->tail_out) {
|
||||
if (os->out) {
|
||||
ffurl_close(os->out);
|
||||
}
|
||||
if (os->out2) {
|
||||
ffurl_close(os->out2);
|
||||
}
|
||||
ffurl_closep(&os->out);
|
||||
ffurl_closep(&os->out2);
|
||||
os->out = os->tail_out;
|
||||
os->out2 = NULL;
|
||||
os->tail_out = NULL;
|
||||
}
|
||||
if (offset >= os->cur_start_pos) {
|
||||
@ -175,10 +170,9 @@ static void ism_free(AVFormatContext *s)
|
||||
return;
|
||||
for (i = 0; i < s->nb_streams; i++) {
|
||||
OutputStream *os = &c->streams[i];
|
||||
ffurl_close(os->out);
|
||||
ffurl_close(os->out2);
|
||||
ffurl_close(os->tail_out);
|
||||
os->out = os->out2 = os->tail_out = NULL;
|
||||
ffurl_closep(&os->out);
|
||||
ffurl_closep(&os->out2);
|
||||
ffurl_closep(&os->tail_out);
|
||||
if (os->ctx && os->ctx_inited)
|
||||
av_write_trailer(os->ctx);
|
||||
if (os->ctx && os->ctx->pb)
|
||||
@ -537,8 +531,7 @@ static int ism_flush(AVFormatContext *s, int final)
|
||||
if (!os->out || os->tail_out)
|
||||
return AVERROR(EIO);
|
||||
|
||||
ffurl_close(os->out);
|
||||
os->out = NULL;
|
||||
ffurl_closep(&os->out);
|
||||
size = os->tail_pos - os->cur_start_pos;
|
||||
if ((ret = parse_fragment(s, filename, &start_ts, &duration, &moof_size, size)) < 0)
|
||||
break;
|
||||
|
@ -59,8 +59,7 @@ static int srtp_close(URLContext *h)
|
||||
SRTPProtoContext *s = h->priv_data;
|
||||
ff_srtp_free(&s->srtp_out);
|
||||
ff_srtp_free(&s->srtp_in);
|
||||
ffurl_close(s->rtp_hd);
|
||||
s->rtp_hd = NULL;
|
||||
ffurl_closep(&s->rtp_hd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags,
|
||||
return ret;
|
||||
c->pos = c->start;
|
||||
if ((ret = slave_seek(h)) < 0) {
|
||||
ffurl_close(c->h);
|
||||
ffurl_closep(&c->h);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
@ -95,7 +95,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags,
|
||||
static int subfile_close(URLContext *h)
|
||||
{
|
||||
SubfileContext *c = h->priv_data;
|
||||
return ffurl_close(c->h);
|
||||
return ffurl_closep(&c->h);
|
||||
}
|
||||
|
||||
static int subfile_read(URLContext *h, unsigned char *buf, int size)
|
||||
|
@ -100,8 +100,7 @@ static int tls_close(URLContext *h)
|
||||
gnutls_deinit(c->session);
|
||||
if (c->cred)
|
||||
gnutls_certificate_free_credentials(c->cred);
|
||||
if (c->tls_shared.tcp)
|
||||
ffurl_close(c->tls_shared.tcp);
|
||||
ffurl_closep(&c->tls_shared.tcp);
|
||||
ff_gnutls_deinit();
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,8 +44,7 @@ static int ff_tls_close(URLContext *h)
|
||||
tls_close(p->ctx);
|
||||
tls_free(p->ctx);
|
||||
}
|
||||
if (p->tls_shared.tcp)
|
||||
ffurl_close(p->tls_shared.tcp);
|
||||
ffurl_closep(&p->tls_shared.tcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,7 @@ static int tls_close(URLContext *h)
|
||||
}
|
||||
if (c->ctx)
|
||||
SSL_CTX_free(c->ctx);
|
||||
if (c->tls_shared.tcp)
|
||||
ffurl_close(c->tls_shared.tcp);
|
||||
ffurl_closep(&c->tls_shared.tcp);
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
|
||||
if (c->url_bio_method)
|
||||
BIO_meth_free(c->url_bio_method);
|
||||
|
@ -138,8 +138,7 @@ static int tls_close(URLContext *h)
|
||||
av_freep(&c->dec_buf);
|
||||
c->dec_buf_size = c->dec_buf_offset = 0;
|
||||
|
||||
if (c->tls_shared.tcp)
|
||||
ffurl_close(c->tls_shared.tcp);
|
||||
ffurl_closep(&c->tls_shared.tcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -251,8 +251,7 @@ static int tls_close(URLContext *h)
|
||||
}
|
||||
if (c->ca_array)
|
||||
CFRelease(c->ca_array);
|
||||
if (c->tls_shared.tcp)
|
||||
ffurl_close(c->tls_shared.tcp);
|
||||
ffurl_closep(&c->tls_shared.tcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user