Skip to content

Commit 6b8e626

Browse files
committed
avformat/tls_openssl: properly set this pkey and free it
Signed-off-by: Jack Lau <jacklau1222@qq.com>
1 parent eabff77 commit 6b8e626

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

libavformat/tls_openssl.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ static av_cold int openssl_init_ca_key_cert(URLContext *h)
812812
int ret;
813813
TLSContext *p = h->priv_data;
814814
TLSShared *c = &p->tls_shared;
815-
EVP_PKEY *pkey = p->pkey;
815+
EVP_PKEY *pkey = NULL;
816816
X509 *cert = NULL;
817817
/* setup ca, private key, certificate */
818818
if (c->ca_file) {
@@ -850,7 +850,7 @@ static av_cold int openssl_init_ca_key_cert(URLContext *h)
850850
goto fail;
851851
}
852852
} else if (p->tls_shared.key_buf) {
853-
pkey = pkey_from_pem_string(p->tls_shared.key_buf, 1);
853+
p->pkey = pkey = pkey_from_pem_string(p->tls_shared.key_buf, 1);
854854
if (SSL_CTX_use_PrivateKey(p->ctx, pkey) != 1) {
855855
av_log(p, AV_LOG_ERROR, "TLS: Init SSL_CTX_use_PrivateKey failed, %s\n", openssl_get_error(p));
856856
ret = AVERROR(EINVAL);
@@ -878,7 +878,7 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
878878
c->is_dtls = 1;
879879
const char* ciphers = "ALL";
880880
#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
881-
EC_KEY *ec_key;
881+
EC_KEY *ec_key = NULL;
882882
#endif
883883
/**
884884
* The profile for OpenSSL's SRTP is SRTP_AES128_CM_SHA1_80, see ssl/d1_srtp.c.
@@ -1007,6 +1007,9 @@ static int dtls_start(URLContext *h, const char *url, int flags, AVDictionary **
10071007

10081008
ret = 0;
10091009
fail:
1010+
#if OPENSSL_VERSION_NUMBER < 0x10002000L // v1.0.2
1011+
EC_KEY_free(ec_key);
1012+
#endif
10101013
return ret;
10111014
}
10121015

0 commit comments

Comments
 (0)