History

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.

Andreas Rheinhardt committed 6 years ago

Commit 82bf41f1 parent af97c9824 files · +43 −71Browse files

Unified · Split

24 files
  1. libavformat/async.c +2 −2
  2. libavformat/cache.c +1 −1
  3. libavformat/concat.c +1 −1
  4. libavformat/crypto.c +1 −2
  5. libavformat/gopher.c +1 −4
  6. libavformat/hlsproto.c +2 −3
  7. libavformat/icecast.c +1 −2
  8. libavformat/mmsh.c +2 −3
  9. libavformat/mmst.c +1 −1
  10. libavformat/rtmpcrypt.c +1 −1
  11. libavformat/rtmphttp.c +1 −1
  12. libavformat/rtmpproto.c +2 −3
  13. libavformat/rtpproto.c +4 −6
  14. libavformat/rtsp.c +7 −10
  15. libavformat/sapdec.c +1 −2
  16. libavformat/sapenc.c +1 −2
  17. libavformat/smoothstreamingenc.c +6 −13
  18. libavformat/srtpproto.c +1 −2
  19. libavformat/subfile.c +2 −2
  20. libavformat/tls_gnutls.c +1 −2
  21. libavformat/tls_libtls.c +1 −2
  22. libavformat/tls_openssl.c +1 −2
  23. libavformat/tls_schannel.c +1 −2
  24. libavformat/tls_securetransport.c +1 −2
libavformat/async.c+2−2
@@ -293,7 +293,7 @@ cond_wakeup_background_fail: · 292 unmodified lines
293293 cond_wakeup_main_fail:
294294 pthread_mutex_destroy(&c->mutex);
295295 mutex_fail:
296− ffurl_close(c->inner);
296+ ffurl_closep(&c->inner);
297297 url_fail:
298298 ring_destroy(&c->ring);
299299 fifo_fail:
@@ -317,7 +317,7 @@ static int async_close(URLContext *h) · 17 unmodified lines
317317 pthread_cond_destroy(&c->cond_wakeup_background);
318318 pthread_cond_destroy(&c->cond_wakeup_main);
319319 pthread_mutex_destroy(&c->mutex);
320− ffurl_close(c->inner);
320+ ffurl_closep(&c->inner);
321321 ring_destroy(&c->ring);
322322
323323 return 0;
libavformat/cache.c+1−1
@@ -310,7 +310,7 @@ static int cache_close(URLContext *h) · 309 unmodified lines
310310 av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename);
311311 av_freep(&c->filename);
312312 }
313− ffurl_close(c->inner);
313+ ffurl_closep(&c->inner);
314314 av_tree_enumerate(c->root, NULL, NULL, enu_free);
315315 av_tree_destroy(c->root);
316316
libavformat/concat.c+1−1
@@ -49,7 +49,7 @@ static av_cold int concat_close(URLContext *h) · 48 unmodified lines
4949 struct concat_nodes *nodes = data->nodes;
5050
5151 for (i = 0; i != data->length; i++)
52− err |= ffurl_close(nodes[i].uc);
52+ err |= ffurl_closep(&nodes[i].uc);
5353
5454 av_freep(&data->nodes);
5555
libavformat/crypto.c+1−2
@@ -385,8 +385,7 @@ static int crypto_close(URLContext *h) · 384 unmodified lines
385385 ret = ffurl_write(c->hd, out_buf, BLOCKSIZE);
386386 }
387387
388− if (c->hd)
389− ffurl_close(c->hd);
388+ ffurl_closep(&c->hd);
390389 av_freep(&c->aes_decrypt);
391390 av_freep(&c->aes_encrypt);
392391 av_freep(&c->write_buf);
libavformat/gopher.c+1−4
@@ -68,10 +68,7 @@ static int gopher_connect(URLContext *h, const char *path) · 67 unmodified lines
6868 static int gopher_close(URLContext *h)
6969 {
7070 GopherContext *s = h->priv_data;
71− if (s->hd) {
72− ffurl_close(s->hd);
73− s->hd = NULL;
74− }
71+ ffurl_closep(&s->hd);
7572 return 0;
7673 }
7774
libavformat/hlsproto.c+2−3
@@ -178,7 +178,7 @@ static int hls_close(URLContext *h) · 177 unmodified lines
178178
179179 free_segment_list(s);
180180 free_variant_list(s);
181− ffurl_close(s->seg_hd);
181+ ffurl_closep(&s->seg_hd);
182182 return 0;
183183 }
184184
@@ -260,8 +260,7 @@ start: · 75 unmodified lines
260260 return ret;
261261 }
262262 if (s->seg_hd) {
263− ffurl_close(s->seg_hd);
264− s->seg_hd = NULL;
263+ ffurl_closep(&s->seg_hd);
265264 s->cur_seq_no++;
266265 }
267266 reload_interval = s->n_segments > 0 ?
libavformat/icecast.c+1−2
@@ -75,8 +75,7 @@ static void cat_header(AVBPrint *bp, const char key[], const char value[]) · 74 unmodified lines
7575 static int icecast_close(URLContext *h)
7676 {
7777 IcecastContext *s = h->priv_data;
78− if (s->hd)
79− ffurl_close(s->hd);
78+ ffurl_closep(&s->hd);
8079 return 0;
8180 }
8281
libavformat/mmsh.c+2−3
@@ -65,8 +65,7 @@ static int mmsh_close(URLContext *h) · 64 unmodified lines
6565 {
6666 MMSHContext *mmsh = (MMSHContext *)h->priv_data;
6767 MMSContext *mms = &mmsh->mms;
68− if (mms->mms_hd)
69− ffurl_closep(&mms->mms_hd);
68+ ffurl_closep(&mms->mms_hd);
7069 av_freep(&mms->streams);
7170 av_freep(&mms->asf_header);
7271 return 0;
@@ -265,7 +264,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim · 192 unmodified lines
265264 }
266265
267266 // close the socket and then reopen it for sending the second play request.
268− ffurl_close(mms->mms_hd);
267+ ffurl_closep(&mms->mms_hd);
269268 memset(headers, 0, sizeof(headers));
270269 if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
271270 &h->interrupt_callback)) < 0) {
libavformat/mmst.c+1−1
@@ -473,7 +473,7 @@ static int mms_close(URLContext *h) · 472 unmodified lines
473473 MMSContext *mms = &mmst->mms;
474474 if(mms->mms_hd) {
475475 send_close_packet(mmst);
476− ffurl_close(mms->mms_hd);
476+ ffurl_closep(&mms->mms_hd);
477477 }
478478
479479 /* free all separately allocated pointers in mms */
libavformat/rtmpcrypt.c+1−1
@@ -240,7 +240,7 @@ static int rtmpe_close(URLContext *h) · 239 unmodified lines
240240 RTMPEContext *rt = h->priv_data;
241241
242242 ff_dh_free(rt->dh);
243− ffurl_close(rt->stream);
243+ ffurl_closep(&rt->stream);
244244
245245 return 0;
246246 }
libavformat/rtmphttp.c+1−1
@@ -176,7 +176,7 @@ static int rtmp_http_close(URLContext *h) · 175 unmodified lines
176176 }
177177
178178 av_freep(&rt->out_data);
179− ffurl_close(rt->stream);
179+ ffurl_closep(&rt->stream);
180180
181181 return ret;
182182 }
libavformat/rtmpproto.c+2−3
@@ -2511,7 +2511,7 @@ static int rtmp_close(URLContext *h) · 2510 unmodified lines
25112511
25122512 free_tracked_methods(rt);
25132513 av_freep(&rt->flv_data);
2514− ffurl_close(rt->stream);
2514+ ffurl_closep(&rt->stream);
25152515 return ret;
25162516 }
25172517
@@ -2824,8 +2824,7 @@ reconnect: · 306 unmodified lines
28242824
28252825 if (rt->do_reconnect) {
28262826 int i;
2827− ffurl_close(rt->stream);
2828− rt->stream = NULL;
2827+ ffurl_closep(&rt->stream);
28292828 rt->do_reconnect = 0;
28302829 rt->nb_invokes = 0;
28312830 for (i = 0; i < 2; i++)
libavformat/rtpproto.c+4−6
@@ -363,10 +363,8 @@ static int rtp_open(URLContext *h, const char *uri, int flags) · 362 unmodified lines
363363 return 0;
364364
365365 fail:
366− if (s->rtp_hd)
367− ffurl_close(s->rtp_hd);
368− if (s->rtcp_hd)
369− ffurl_close(s->rtcp_hd);
366+ ffurl_closep(&s->rtp_hd);
367+ ffurl_closep(&s->rtcp_hd);
370368 ffurl_closep(&s->fec_hd);
371369 av_free(fec_protocol);
372370 av_dict_free(&fec_opts);
@@ -506,8 +504,8 @@ static int rtp_close(URLContext *h) · 133 unmodified lines
506504
507505 ff_ip_reset_filters(&s->filters);
508506
509− ffurl_close(s->rtp_hd);
510− ffurl_close(s->rtcp_hd);
507+ ffurl_closep(&s->rtp_hd);
508+ ffurl_closep(&s->rtcp_hd);
511509 ffurl_closep(&s->fec_hd);
512510 return 0;
513511 }
libavformat/rtsp.c+7−10
@@ -763,9 +763,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets) · 762 unmodified lines
763763 ff_rtp_parse_close(rtsp_st->transport_priv);
764764 }
765765 rtsp_st->transport_priv = NULL;
766− if (rtsp_st->rtp_handle)
767− ffurl_close(rtsp_st->rtp_handle);
768− rtsp_st->rtp_handle = NULL;
766+ ffurl_closep(&rtsp_st->rtp_handle);
769767 }
770768 }
771769
@@ -1666,9 +1664,10 @@ fail: · 894 unmodified lines
16661664 void ff_rtsp_close_connections(AVFormatContext *s)
16671665 {
16681666 RTSPState *rt = s->priv_data;
1669− if (rt->rtsp_hd_out != rt->rtsp_hd) ffurl_close(rt->rtsp_hd_out);
1670− ffurl_close(rt->rtsp_hd);
1671− rt->rtsp_hd = rt->rtsp_hd_out = NULL;
1667+ if (rt->rtsp_hd_out != rt->rtsp_hd)
1668+ ffurl_closep(&rt->rtsp_hd_out);
1669+ rt->rtsp_hd_out = NULL;
1670+ ffurl_closep(&rt->rtsp_hd);
16721671 }
16731672
16741673 int ff_rtsp_connect(AVFormatContext *s)
@@ -2496,8 +2495,7 @@ static int rtp_read_header(AVFormatContext *s) · 821 unmodified lines
24962495 break;
24972496 }
24982497 getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);
2499− ffurl_close(in);
2500− in = NULL;
2498+ ffurl_closep(&in);
25012499
25022500 par = avcodec_parameters_alloc();
25032501 if (!par) {
@@ -2571,8 +2569,7 @@ fail_nobuf: · 67 unmodified lines
25712569 av_bprint_finalize(&sdp, NULL);
25722570 fail:
25732571 avcodec_parameters_free(&par);
2574− if (in)
2575− ffurl_close(in);
2572+ ffurl_closep(&in);
25762573 ff_network_close();
25772574 return ret;
25782575 }
libavformat/sapdec.c+1−2
@@ -54,8 +54,7 @@ static int sap_read_close(AVFormatContext *s) · 53 unmodified lines
5454 struct SAPState *sap = s->priv_data;
5555 if (sap->sdp_ctx)
5656 avformat_close_input(&sap->sdp_ctx);
57− if (sap->ann_fd)
58− ffurl_close(sap->ann_fd);
57+ ffurl_closep(&sap->ann_fd);
5958 av_freep(&sap->sdp);
6059 ff_network_close();
6160 return 0;
libavformat/sapenc.c+1−2
@@ -60,8 +60,7 @@ static int sap_write_close(AVFormatContext *s) · 59 unmodified lines
6060 }
6161
6262 av_freep(&sap->ann);
63− if (sap->ann_fd)
64− ffurl_close(sap->ann_fd);
63+ ffurl_closep(&sap->ann_fd);
6564 ff_network_close();
6665 return 0;
6766 }
libavformat/smoothstreamingenc.c+6−13
@@ -99,14 +99,9 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence) · 98 unmodified lines
9999 if (whence != SEEK_SET)
100100 return AVERROR(ENOSYS);
101101 if (os->tail_out) {
102− if (os->out) {
103− ffurl_close(os->out);
104− }
105− if (os->out2) {
106− ffurl_close(os->out2);
107− }
102+ ffurl_closep(&os->out);
103+ ffurl_closep(&os->out2);
108104 os->out = os->tail_out;
109− os->out2 = NULL;
110105 os->tail_out = NULL;
111106 }
112107 if (offset >= os->cur_start_pos) {
@@ -175,10 +170,9 @@ static void ism_free(AVFormatContext *s) · 62 unmodified lines
175170 return;
176171 for (i = 0; i < s->nb_streams; i++) {
177172 OutputStream *os = &c->streams[i];
178− ffurl_close(os->out);
179− ffurl_close(os->out2);
180− ffurl_close(os->tail_out);
181− os->out = os->out2 = os->tail_out = NULL;
173+ ffurl_closep(&os->out);
174+ ffurl_closep(&os->out2);
175+ ffurl_closep(&os->tail_out);
182176 if (os->ctx && os->ctx_inited)
183177 av_write_trailer(os->ctx);
184178 if (os->ctx && os->ctx->pb)
@@ -537,8 +531,7 @@ static int ism_flush(AVFormatContext *s, int final) · 352 unmodified lines
537531 if (!os->out || os->tail_out)
538532 return AVERROR(EIO);
539533
540− ffurl_close(os->out);
541− os->out = NULL;
534+ ffurl_closep(&os->out);
542535 size = os->tail_pos - os->cur_start_pos;
543536 if ((ret = parse_fragment(s, filename, &start_ts, &duration, &moof_size, size)) < 0)
544537 break;
libavformat/srtpproto.c+1−2
@@ -59,8 +59,7 @@ static int srtp_close(URLContext *h) · 58 unmodified lines
5959 SRTPProtoContext *s = h->priv_data;
6060 ff_srtp_free(&s->srtp_out);
6161 ff_srtp_free(&s->srtp_in);
62− ffurl_close(s->rtp_hd);
63− s->rtp_hd = NULL;
62+ ffurl_closep(&s->rtp_hd);
6463 return 0;
6564 }
6665
libavformat/subfile.c+2−2
@@ -86,7 +86,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags, · 85 unmodified lines
8686 return ret;
8787 c->pos = c->start;
8888 if ((ret = slave_seek(h)) < 0) {
89− ffurl_close(c->h);
89+ ffurl_closep(&c->h);
9090 return ret;
9191 }
9292 return 0;
@@ -95,7 +95,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags, · 2 unmodified lines
9595 static int subfile_close(URLContext *h)
9696 {
9797 SubfileContext *c = h->priv_data;
98− return ffurl_close(c->h);
98+ return ffurl_closep(&c->h);
9999 }
100100
101101 static int subfile_read(URLContext *h, unsigned char *buf, int size)
libavformat/tls_gnutls.c+1−2
@@ -100,8 +100,7 @@ static int tls_close(URLContext *h) · 99 unmodified lines
100100 gnutls_deinit(c->session);
101101 if (c->cred)
102102 gnutls_certificate_free_credentials(c->cred);
103− if (c->tls_shared.tcp)
104− ffurl_close(c->tls_shared.tcp);
103+ ffurl_closep(&c->tls_shared.tcp);
105104 ff_gnutls_deinit();
106105 return 0;
107106 }
libavformat/tls_libtls.c+1−2
@@ -44,8 +44,7 @@ static int ff_tls_close(URLContext *h) · 43 unmodified lines
4444 tls_close(p->ctx);
4545 tls_free(p->ctx);
4646 }
47− if (p->tls_shared.tcp)
48− ffurl_close(p->tls_shared.tcp);
47+ ffurl_closep(&p->tls_shared.tcp);
4948 return 0;
5049 }
5150
libavformat/tls_openssl.c+1−2
@@ -142,8 +142,7 @@ static int tls_close(URLContext *h) · 141 unmodified lines
142142 }
143143 if (c->ctx)
144144 SSL_CTX_free(c->ctx);
145− if (c->tls_shared.tcp)
146− ffurl_close(c->tls_shared.tcp);
145+ ffurl_closep(&c->tls_shared.tcp);
147146 #if OPENSSL_VERSION_NUMBER >= 0x1010000fL
148147 if (c->url_bio_method)
149148 BIO_meth_free(c->url_bio_method);
libavformat/tls_schannel.c+1−2
@@ -138,8 +138,7 @@ static int tls_close(URLContext *h) · 137 unmodified lines
138138 av_freep(&c->dec_buf);
139139 c->dec_buf_size = c->dec_buf_offset = 0;
140140
141− if (c->tls_shared.tcp)
142− ffurl_close(c->tls_shared.tcp);
141+ ffurl_closep(&c->tls_shared.tcp);
143142 return 0;
144143 }
145144
libavformat/tls_securetransport.c+1−2
@@ -251,8 +251,7 @@ static int tls_close(URLContext *h) · 250 unmodified lines
251251 }
252252 if (c->ca_array)
253253 CFRelease(c->ca_array);
254− if (c->tls_shared.tcp)
255− ffurl_close(c->tls_shared.tcp);
254+ ffurl_closep(&c->tls_shared.tcp);
256255 return 0;
257256 }
258257

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t