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
293cond_wakeup_main_fail:293cond_wakeup_main_fail:
294 pthread_mutex_destroy(&c->mutex);294 pthread_mutex_destroy(&c->mutex);
295mutex_fail:295mutex_fail:
296 ffurl_close(c->inner);296 ffurl_closep(&c->inner);
297url_fail:297url_fail:
298 ring_destroy(&c->ring);298 ring_destroy(&c->ring);
299fifo_fail:299fifo_fail:
@@ -317,7 +317,7 @@ static int async_close(URLContext *h) · 17 unmodified lines
317 pthread_cond_destroy(&c->cond_wakeup_background);317 pthread_cond_destroy(&c->cond_wakeup_background);
318 pthread_cond_destroy(&c->cond_wakeup_main);318 pthread_cond_destroy(&c->cond_wakeup_main);
319 pthread_mutex_destroy(&c->mutex);319 pthread_mutex_destroy(&c->mutex);
320 ffurl_close(c->inner);320 ffurl_closep(&c->inner);
321 ring_destroy(&c->ring);321 ring_destroy(&c->ring);
322 322
323 return 0;323 return 0;
libavformat/cache.c+1−1
@@ -310,7 +310,7 @@ static int cache_close(URLContext *h) · 309 unmodified lines
310 av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename);310 av_log(h, AV_LOG_ERROR, "Could not delete %s.\n", c->filename);
311 av_freep(&c->filename);311 av_freep(&c->filename);
312 }312 }
313 ffurl_close(c->inner);313 ffurl_closep(&c->inner);
314 av_tree_enumerate(c->root, NULL, NULL, enu_free);314 av_tree_enumerate(c->root, NULL, NULL, enu_free);
315 av_tree_destroy(c->root);315 av_tree_destroy(c->root);
316 316
libavformat/concat.c+1−1
@@ -49,7 +49,7 @@ static av_cold int concat_close(URLContext *h) · 48 unmodified lines
49 struct concat_nodes *nodes = data->nodes;49 struct concat_nodes *nodes = data->nodes;
50 50
51 for (i = 0; i != data->length; i++)51 for (i = 0; i != data->length; i++)
52 err |= ffurl_close(nodes[i].uc);52 err |= ffurl_closep(&nodes[i].uc);
53 53
54 av_freep(&data->nodes);54 av_freep(&data->nodes);
55 55
libavformat/crypto.c+1−2
@@ -385,8 +385,7 @@ static int crypto_close(URLContext *h) · 384 unmodified lines
385 ret = ffurl_write(c->hd, out_buf, BLOCKSIZE);385 ret = ffurl_write(c->hd, out_buf, BLOCKSIZE);
386 }386 }
387 387
388 if (c->hd)388 ffurl_closep(&c->hd);
389 ffurl_close(c->hd);
390 av_freep(&c->aes_decrypt);389 av_freep(&c->aes_decrypt);
391 av_freep(&c->aes_encrypt);390 av_freep(&c->aes_encrypt);
392 av_freep(&c->write_buf);391 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
68static int gopher_close(URLContext *h)68static int gopher_close(URLContext *h)
69{69{
70 GopherContext *s = h->priv_data;70 GopherContext *s = h->priv_data;
71 if (s->hd) {71 ffurl_closep(&s->hd);
72 ffurl_close(s->hd);
73 s->hd = NULL;
74 }
75 return 0;72 return 0;
76}73}
77 74
libavformat/hlsproto.c+2−3
@@ -178,7 +178,7 @@ static int hls_close(URLContext *h) · 177 unmodified lines
178 178
179 free_segment_list(s);179 free_segment_list(s);
180 free_variant_list(s);180 free_variant_list(s);
181 ffurl_close(s->seg_hd);181 ffurl_closep(&s->seg_hd);
182 return 0;182 return 0;
183}183}
184 184
@@ -260,8 +260,7 @@ start: · 75 unmodified lines
260 return ret;260 return ret;
261 }261 }
262 if (s->seg_hd) {262 if (s->seg_hd) {
263 ffurl_close(s->seg_hd);263 ffurl_closep(&s->seg_hd);
264 s->seg_hd = NULL;
265 s->cur_seq_no++;264 s->cur_seq_no++;
266 }265 }
267 reload_interval = s->n_segments > 0 ?266 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
75static int icecast_close(URLContext *h)75static int icecast_close(URLContext *h)
76{76{
77 IcecastContext *s = h->priv_data;77 IcecastContext *s = h->priv_data;
78 if (s->hd)78 ffurl_closep(&s->hd);
79 ffurl_close(s->hd);
80 return 0;79 return 0;
81}80}
82 81
libavformat/mmsh.c+2−3
@@ -65,8 +65,7 @@ static int mmsh_close(URLContext *h) · 64 unmodified lines
65{65{
66 MMSHContext *mmsh = (MMSHContext *)h->priv_data;66 MMSHContext *mmsh = (MMSHContext *)h->priv_data;
67 MMSContext *mms = &mmsh->mms;67 MMSContext *mms = &mmsh->mms;
68 if (mms->mms_hd)68 ffurl_closep(&mms->mms_hd);
69 ffurl_closep(&mms->mms_hd);
70 av_freep(&mms->streams);69 av_freep(&mms->streams);
71 av_freep(&mms->asf_header);70 av_freep(&mms->asf_header);
72 return 0;71 return 0;
@@ -265,7 +264,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim · 192 unmodified lines
265 }264 }
266 265
267 // close the socket and then reopen it for sending the second play request.266 // 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);
269 memset(headers, 0, sizeof(headers));268 memset(headers, 0, sizeof(headers));
270 if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,269 if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ,
271 &h->interrupt_callback)) < 0) {270 &h->interrupt_callback)) < 0) {
libavformat/mmst.c+1−1
@@ -473,7 +473,7 @@ static int mms_close(URLContext *h) · 472 unmodified lines
473 MMSContext *mms = &mmst->mms;473 MMSContext *mms = &mmst->mms;
474 if(mms->mms_hd) {474 if(mms->mms_hd) {
475 send_close_packet(mmst);475 send_close_packet(mmst);
476 ffurl_close(mms->mms_hd);476 ffurl_closep(&mms->mms_hd);
477 }477 }
478 478
479 /* free all separately allocated pointers in mms */479 /* 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
240 RTMPEContext *rt = h->priv_data;240 RTMPEContext *rt = h->priv_data;
241 241
242 ff_dh_free(rt->dh);242 ff_dh_free(rt->dh);
243 ffurl_close(rt->stream);243 ffurl_closep(&rt->stream);
244 244
245 return 0;245 return 0;
246}246}
libavformat/rtmphttp.c+1−1
@@ -176,7 +176,7 @@ static int rtmp_http_close(URLContext *h) · 175 unmodified lines
176 }176 }
177 177
178 av_freep(&rt->out_data);178 av_freep(&rt->out_data);
179 ffurl_close(rt->stream);179 ffurl_closep(&rt->stream);
180 180
181 return ret;181 return ret;
182}182}
libavformat/rtmpproto.c+2−3
@@ -2511,7 +2511,7 @@ static int rtmp_close(URLContext *h) · 2510 unmodified lines
2511 2511
2512 free_tracked_methods(rt);2512 free_tracked_methods(rt);
2513 av_freep(&rt->flv_data);2513 av_freep(&rt->flv_data);
2514 ffurl_close(rt->stream);2514 ffurl_closep(&rt->stream);
2515 return ret;2515 return ret;
2516}2516}
2517 2517
@@ -2824,8 +2824,7 @@ reconnect: · 306 unmodified lines
2824 2824
2825 if (rt->do_reconnect) {2825 if (rt->do_reconnect) {
2826 int i;2826 int i;
2827 ffurl_close(rt->stream);2827 ffurl_closep(&rt->stream);
2828 rt->stream = NULL;
2829 rt->do_reconnect = 0;2828 rt->do_reconnect = 0;
2830 rt->nb_invokes = 0;2829 rt->nb_invokes = 0;
2831 for (i = 0; i < 2; i++)2830 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
363 return 0;363 return 0;
364 364
365 fail:365 fail:
366 if (s->rtp_hd)366 ffurl_closep(&s->rtp_hd);
367 ffurl_close(s->rtp_hd);367 ffurl_closep(&s->rtcp_hd);
368 if (s->rtcp_hd)
369 ffurl_close(s->rtcp_hd);
370 ffurl_closep(&s->fec_hd);368 ffurl_closep(&s->fec_hd);
371 av_free(fec_protocol);369 av_free(fec_protocol);
372 av_dict_free(&fec_opts);370 av_dict_free(&fec_opts);
@@ -506,8 +504,8 @@ static int rtp_close(URLContext *h) · 133 unmodified lines
506 504
507 ff_ip_reset_filters(&s->filters);505 ff_ip_reset_filters(&s->filters);
508 506
509 ffurl_close(s->rtp_hd);507 ffurl_closep(&s->rtp_hd);
510 ffurl_close(s->rtcp_hd);508 ffurl_closep(&s->rtcp_hd);
511 ffurl_closep(&s->fec_hd);509 ffurl_closep(&s->fec_hd);
512 return 0;510 return 0;
513}511}
libavformat/rtsp.c+7−10
@@ -763,9 +763,7 @@ void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets) · 762 unmodified lines
763 ff_rtp_parse_close(rtsp_st->transport_priv);763 ff_rtp_parse_close(rtsp_st->transport_priv);
764 }764 }
765 rtsp_st->transport_priv = NULL;765 rtsp_st->transport_priv = NULL;
766 if (rtsp_st->rtp_handle)766 ffurl_closep(&rtsp_st->rtp_handle);
767 ffurl_close(rtsp_st->rtp_handle);
768 rtsp_st->rtp_handle = NULL;
769 }767 }
770}768}
771 769
@@ -1666,9 +1664,10 @@ fail: · 894 unmodified lines
1666void ff_rtsp_close_connections(AVFormatContext *s)1664void ff_rtsp_close_connections(AVFormatContext *s)
1667{1665{
1668 RTSPState *rt = s->priv_data;1666 RTSPState *rt = s->priv_data;
1669 if (rt->rtsp_hd_out != rt->rtsp_hd) ffurl_close(rt->rtsp_hd_out);1667 if (rt->rtsp_hd_out != rt->rtsp_hd)
1670 ffurl_close(rt->rtsp_hd);1668 ffurl_closep(&rt->rtsp_hd_out);
1671 rt->rtsp_hd = rt->rtsp_hd_out = NULL;1669 rt->rtsp_hd_out = NULL;
1670 ffurl_closep(&rt->rtsp_hd);
1672}1671}
1673 1672
1674int ff_rtsp_connect(AVFormatContext *s)1673int ff_rtsp_connect(AVFormatContext *s)
@@ -2496,8 +2495,7 @@ static int rtp_read_header(AVFormatContext *s) · 821 unmodified lines
2496 break;2495 break;
2497 }2496 }
2498 getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);2497 getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen);
2499 ffurl_close(in);2498 ffurl_closep(&in);
2500 in = NULL;
2501 2499
2502 par = avcodec_parameters_alloc();2500 par = avcodec_parameters_alloc();
2503 if (!par) {2501 if (!par) {
@@ -2571,8 +2569,7 @@ fail_nobuf: · 67 unmodified lines
2571 av_bprint_finalize(&sdp, NULL);2569 av_bprint_finalize(&sdp, NULL);
2572fail:2570fail:
2573 avcodec_parameters_free(&par);2571 avcodec_parameters_free(&par);
2574 if (in)2572 ffurl_closep(&in);
2575 ffurl_close(in);
2576 ff_network_close();2573 ff_network_close();
2577 return ret;2574 return ret;
2578}2575}
libavformat/sapdec.c+1−2
@@ -54,8 +54,7 @@ static int sap_read_close(AVFormatContext *s) · 53 unmodified lines
54 struct SAPState *sap = s->priv_data;54 struct SAPState *sap = s->priv_data;
55 if (sap->sdp_ctx)55 if (sap->sdp_ctx)
56 avformat_close_input(&sap->sdp_ctx);56 avformat_close_input(&sap->sdp_ctx);
57 if (sap->ann_fd)57 ffurl_closep(&sap->ann_fd);
58 ffurl_close(sap->ann_fd);
59 av_freep(&sap->sdp);58 av_freep(&sap->sdp);
60 ff_network_close();59 ff_network_close();
61 return 0;60 return 0;
libavformat/sapenc.c+1−2
@@ -60,8 +60,7 @@ static int sap_write_close(AVFormatContext *s) · 59 unmodified lines
60 }60 }
61 61
62 av_freep(&sap->ann);62 av_freep(&sap->ann);
63 if (sap->ann_fd)63 ffurl_closep(&sap->ann_fd);
64 ffurl_close(sap->ann_fd);
65 ff_network_close();64 ff_network_close();
66 return 0;65 return 0;
67}66}
libavformat/smoothstreamingenc.c+6−13
@@ -99,14 +99,9 @@ static int64_t ism_seek(void *opaque, int64_t offset, int whence) · 98 unmodified lines
99 if (whence != SEEK_SET)99 if (whence != SEEK_SET)
100 return AVERROR(ENOSYS);100 return AVERROR(ENOSYS);
101 if (os->tail_out) {101 if (os->tail_out) {
102 if (os->out) {102 ffurl_closep(&os->out);
103 ffurl_close(os->out);103 ffurl_closep(&os->out2);
104 }
105 if (os->out2) {
106 ffurl_close(os->out2);
107 }
108 os->out = os->tail_out;104 os->out = os->tail_out;
109 os->out2 = NULL;
110 os->tail_out = NULL;105 os->tail_out = NULL;
111 }106 }
112 if (offset >= os->cur_start_pos) {107 if (offset >= os->cur_start_pos) {
@@ -175,10 +170,9 @@ static void ism_free(AVFormatContext *s) · 62 unmodified lines
175 return;170 return;
176 for (i = 0; i < s->nb_streams; i++) {171 for (i = 0; i < s->nb_streams; i++) {
177 OutputStream *os = &c->streams[i];172 OutputStream *os = &c->streams[i];
178 ffurl_close(os->out);173 ffurl_closep(&os->out);
179 ffurl_close(os->out2);174 ffurl_closep(&os->out2);
180 ffurl_close(os->tail_out);175 ffurl_closep(&os->tail_out);
181 os->out = os->out2 = os->tail_out = NULL;
182 if (os->ctx && os->ctx_inited)176 if (os->ctx && os->ctx_inited)
183 av_write_trailer(os->ctx);177 av_write_trailer(os->ctx);
184 if (os->ctx && os->ctx->pb)178 if (os->ctx && os->ctx->pb)
@@ -537,8 +531,7 @@ static int ism_flush(AVFormatContext *s, int final) · 352 unmodified lines
537 if (!os->out || os->tail_out)531 if (!os->out || os->tail_out)
538 return AVERROR(EIO);532 return AVERROR(EIO);
539 533
540 ffurl_close(os->out);534 ffurl_closep(&os->out);
541 os->out = NULL;
542 size = os->tail_pos - os->cur_start_pos;535 size = os->tail_pos - os->cur_start_pos;
543 if ((ret = parse_fragment(s, filename, &start_ts, &duration, &moof_size, size)) < 0)536 if ((ret = parse_fragment(s, filename, &start_ts, &duration, &moof_size, size)) < 0)
544 break;537 break;
libavformat/srtpproto.c+1−2
@@ -59,8 +59,7 @@ static int srtp_close(URLContext *h) · 58 unmodified lines
59 SRTPProtoContext *s = h->priv_data;59 SRTPProtoContext *s = h->priv_data;
60 ff_srtp_free(&s->srtp_out);60 ff_srtp_free(&s->srtp_out);
61 ff_srtp_free(&s->srtp_in);61 ff_srtp_free(&s->srtp_in);
62 ffurl_close(s->rtp_hd);62 ffurl_closep(&s->rtp_hd);
63 s->rtp_hd = NULL;
64 return 0;63 return 0;
65}64}
66 65
libavformat/subfile.c+2−2
@@ -86,7 +86,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags, · 85 unmodified lines
86 return ret;86 return ret;
87 c->pos = c->start;87 c->pos = c->start;
88 if ((ret = slave_seek(h)) < 0) {88 if ((ret = slave_seek(h)) < 0) {
89 ffurl_close(c->h);89 ffurl_closep(&c->h);
90 return ret;90 return ret;
91 }91 }
92 return 0;92 return 0;
@@ -95,7 +95,7 @@ static int subfile_open(URLContext *h, const char *filename, int flags, · 2 unmodified lines
95static int subfile_close(URLContext *h)95static int subfile_close(URLContext *h)
96{96{
97 SubfileContext *c = h->priv_data;97 SubfileContext *c = h->priv_data;
98 return ffurl_close(c->h);98 return ffurl_closep(&c->h);
99}99}
100 100
101static int subfile_read(URLContext *h, unsigned char *buf, int size)101static 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
100 gnutls_deinit(c->session);100 gnutls_deinit(c->session);
101 if (c->cred)101 if (c->cred)
102 gnutls_certificate_free_credentials(c->cred);102 gnutls_certificate_free_credentials(c->cred);
103 if (c->tls_shared.tcp)103 ffurl_closep(&c->tls_shared.tcp);
104 ffurl_close(c->tls_shared.tcp);
105 ff_gnutls_deinit();104 ff_gnutls_deinit();
106 return 0;105 return 0;
107}106}
libavformat/tls_libtls.c+1−2
@@ -44,8 +44,7 @@ static int ff_tls_close(URLContext *h) · 43 unmodified lines
44 tls_close(p->ctx);44 tls_close(p->ctx);
45 tls_free(p->ctx);45 tls_free(p->ctx);
46 }46 }
47 if (p->tls_shared.tcp)47 ffurl_closep(&p->tls_shared.tcp);
48 ffurl_close(p->tls_shared.tcp);
49 return 0;48 return 0;
50}49}
51 50
libavformat/tls_openssl.c+1−2
@@ -142,8 +142,7 @@ static int tls_close(URLContext *h) · 141 unmodified lines
142 }142 }
143 if (c->ctx)143 if (c->ctx)
144 SSL_CTX_free(c->ctx);144 SSL_CTX_free(c->ctx);
145 if (c->tls_shared.tcp)145 ffurl_closep(&c->tls_shared.tcp);
146 ffurl_close(c->tls_shared.tcp);
147#if OPENSSL_VERSION_NUMBER >= 0x1010000fL146#if OPENSSL_VERSION_NUMBER >= 0x1010000fL
148 if (c->url_bio_method)147 if (c->url_bio_method)
149 BIO_meth_free(c->url_bio_method);148 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
138 av_freep(&c->dec_buf);138 av_freep(&c->dec_buf);
139 c->dec_buf_size = c->dec_buf_offset = 0;139 c->dec_buf_size = c->dec_buf_offset = 0;
140 140
141 if (c->tls_shared.tcp)141 ffurl_closep(&c->tls_shared.tcp);
142 ffurl_close(c->tls_shared.tcp);
143 return 0;142 return 0;
144}143}
145 144
libavformat/tls_securetransport.c+1−2
@@ -251,8 +251,7 @@ static int tls_close(URLContext *h) · 250 unmodified lines
251 }251 }
252 if (c->ca_array)252 if (c->ca_array)
253 CFRelease(c->ca_array);253 CFRelease(c->ca_array);
254 if (c->tls_shared.tcp)254 ffurl_closep(&c->tls_shared.tcp);
255 ffurl_close(c->tls_shared.tcp);
256 return 0;255 return 0;
257}256}
258 257

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