Skip to content

Commit 8d124b0

Browse files
committed
WHIP: Free bio_in if ENOMEM.
1 parent b65e953 commit 8d124b0

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

libavformat/whip.c

+25-10
Original file line numberDiff line numberDiff line change
@@ -730,15 +730,17 @@ static av_cold int openssl_dtls_init_context(DTLSContext *ctx)
730730
dtls_ctx = ctx->dtls_ctx = SSL_CTX_new(DTLS_method());
731731
#endif
732732
if (!dtls_ctx) {
733-
return AVERROR(ENOMEM);
733+
ret = AVERROR(ENOMEM);
734+
goto end;
734735
}
735736

736737
#if OPENSSL_VERSION_NUMBER >= 0x10002000L /* OpenSSL 1.0.2 */
737738
/* For ECDSA, we could set the curves list. */
738739
if (SSL_CTX_set1_curves_list(dtls_ctx, curves) != 1) {
739740
av_log(ctx, AV_LOG_ERROR, "DTLS: Init SSL_CTX_set1_curves_list failed, curves=%s, %s\n",
740741
curves, openssl_get_error(ctx));
741-
return AVERROR(EINVAL);
742+
ret = AVERROR(EINVAL);
743+
return ret;
742744
}
743745
#endif
744746

@@ -758,16 +760,19 @@ static av_cold int openssl_dtls_init_context(DTLSContext *ctx)
758760
if (SSL_CTX_set_cipher_list(dtls_ctx, ciphers) != 1) {
759761
av_log(ctx, AV_LOG_ERROR, "DTLS: Init SSL_CTX_set_cipher_list failed, ciphers=%s, %s\n",
760762
ciphers, openssl_get_error(ctx));
761-
return AVERROR(EINVAL);
763+
ret = AVERROR(EINVAL);
764+
return ret;
762765
}
763766
/* Setup the certificate. */
764767
if (SSL_CTX_use_certificate(dtls_ctx, dtls_cert) != 1) {
765768
av_log(ctx, AV_LOG_ERROR, "DTLS: Init SSL_CTX_use_certificate failed, %s\n", openssl_get_error(ctx));
766-
return AVERROR(EINVAL);
769+
ret = AVERROR(EINVAL);
770+
return ret;
767771
}
768772
if (SSL_CTX_use_PrivateKey(dtls_ctx, dtls_pkey) != 1) {
769773
av_log(ctx, AV_LOG_ERROR, "DTLS: Init SSL_CTX_use_PrivateKey failed, %s\n", openssl_get_error(ctx));
770-
return AVERROR(EINVAL);
774+
ret = AVERROR(EINVAL);
775+
return ret;
771776
}
772777

773778
/* Server will send Certificate Request. */
@@ -781,13 +786,15 @@ static av_cold int openssl_dtls_init_context(DTLSContext *ctx)
781786
if (SSL_CTX_set_tlsext_use_srtp(dtls_ctx, profiles)) {
782787
av_log(ctx, AV_LOG_ERROR, "DTLS: Init SSL_CTX_set_tlsext_use_srtp failed, profiles=%s, %s\n",
783788
profiles, openssl_get_error(ctx));
784-
return AVERROR(EINVAL);
789+
ret = AVERROR(EINVAL);
790+
return ret;
785791
}
786792

787793
/* The dtls should not be created unless the dtls_ctx has been initialized. */
788794
dtls = ctx->dtls = SSL_new(dtls_ctx);
789795
if (!dtls) {
790-
return AVERROR(ENOMEM);
796+
ret = AVERROR(ENOMEM);
797+
goto end;
791798
}
792799

793800
/* Setup the callback for logging. */
@@ -804,14 +811,16 @@ static av_cold int openssl_dtls_init_context(DTLSContext *ctx)
804811
DTLS_set_link_mtu(dtls, ctx->mtu);
805812
#endif
806813

807-
bio_in = ctx->bio_in = BIO_new(BIO_s_mem());
814+
bio_in = BIO_new(BIO_s_mem());
808815
if (!bio_in) {
809-
return AVERROR(ENOMEM);
816+
ret = AVERROR(ENOMEM);
817+
goto end;
810818
}
811819

812820
bio_out = BIO_new(BIO_s_mem());
813821
if (!bio_out) {
814-
return AVERROR(ENOMEM);
822+
ret = AVERROR(ENOMEM);
823+
goto end;
815824
}
816825

817826
/**
@@ -835,8 +844,14 @@ static av_cold int openssl_dtls_init_context(DTLSContext *ctx)
835844
#endif
836845
BIO_set_callback_arg(bio_out, (char*)ctx);
837846

847+
ctx->bio_in = bio_in;
838848
SSL_set_bio(dtls, bio_in, bio_out);
849+
/* Now the bio_in and bio_out are owned by dtls, so we should set them to NULL. */
850+
bio_in = bio_out = NULL;
839851

852+
end:
853+
BIO_free(bio_in);
854+
BIO_free(bio_out);
840855
return ret;
841856
}
842857

0 commit comments

Comments
 (0)