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