Unified · Split
| @@ -161,8 +161,8 @@ int ff_ssl_read_key_cert(char *key_url, char *cert_url, char *key_buf, size_t ke · 160 unmodified lines | |||
| 161 | int ret = 0; | 161 | int ret = 0; |
| 162 | BIO *key_b = NULL, *cert_b = NULL; | 162 | BIO *key_b = NULL, *cert_b = NULL; |
| 163 | AVBPrint key_bp, cert_bp; | 163 | AVBPrint key_bp, cert_bp; |
| 164 | EVP_PKEY *pkey; | 164 | EVP_PKEY *pkey = NULL; |
| 165 | X509 *cert; | 165 | X509 *cert = NULL; |
| 166 | char *key_tem = NULL, *cert_tem = NULL; | 166 | char *key_tem = NULL, *cert_tem = NULL; |
| 167 | 167 | ||
| 168 | /* To prevent a crash during cleanup, always initialize it. */ | 168 | /* To prevent a crash during cleanup, always initialize it. */ |
| @@ -230,6 +230,8 @@ end: · 61 unmodified lines | |||
| 230 | av_bprint_finalize(&cert_bp, NULL); | 230 | av_bprint_finalize(&cert_bp, NULL); |
| 231 | av_free(key_tem); | 231 | av_free(key_tem); |
| 232 | av_free(cert_tem); | 232 | av_free(cert_tem); |
| 233 | EVP_PKEY_free(pkey); | ||
| 234 | X509_free(cert); | ||
| 233 | return ret; | 235 | return ret; |
| 234 | } | 236 | } |
| 235 | 237 | ||
| @@ -255,7 +257,16 @@ static int openssl_gen_private_key(EVP_PKEY **pkey, EC_KEY **eckey) · 19 unmodified lines | |||
| 255 | 257 | ||
| 256 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ | 258 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ |
| 257 | *pkey = EVP_PKEY_new(); | 259 | *pkey = EVP_PKEY_new(); |
| 260 | if (!*pkey) | ||
| 261 | return AVERROR(ENOMEM); | ||
| 262 | |||
| 258 | *eckey = EC_KEY_new(); | 263 | *eckey = EC_KEY_new(); |
| 264 | if (!*eckey) { | ||
| 265 | EVP_PKEY_free(*pkey); | ||
| 266 | *pkey = NULL; | ||
| 267 | return AVERROR(ENOMEM); | ||
| 268 | } | ||
| 269 | |||
| 259 | ecgroup = EC_GROUP_new_by_curve_name(curve); | 270 | ecgroup = EC_GROUP_new_by_curve_name(curve); |
| 260 | if (!ecgroup) { | 271 | if (!ecgroup) { |
| 261 | av_log(NULL, AV_LOG_ERROR, "TLS: Create EC group by curve=%d failed, %s", curve, ERR_error_string(ERR_get_error(), NULL)); | 272 | av_log(NULL, AV_LOG_ERROR, "TLS: Create EC group by curve=%d failed, %s", curve, ERR_error_string(ERR_get_error(), NULL)); |
| @@ -287,6 +298,10 @@ static int openssl_gen_private_key(EVP_PKEY **pkey, EC_KEY **eckey) · 25 unmodified lines | |||
| 287 | 298 | ||
| 288 | einval_end: | 299 | einval_end: |
| 289 | ret = AVERROR(EINVAL); | 300 | ret = AVERROR(EINVAL); |
| 301 | EC_KEY_free(*eckey); | ||
| 302 | EVP_PKEY_free(*pkey); | ||
| 303 | *eckey = NULL; | ||
| 304 | *pkey = NULL; | ||
| 290 | end: | 305 | end: |
| 291 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ | 306 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ |
| 292 | EC_GROUP_free(ecgroup); | 307 | EC_GROUP_free(ecgroup); |
| @@ -368,6 +383,10 @@ enomem_end: · 75 unmodified lines | |||
| 368 | einval_end: | 383 | einval_end: |
| 369 | ret = AVERROR(EINVAL); | 384 | ret = AVERROR(EINVAL); |
| 370 | end: | 385 | end: |
| 386 | if (ret) { | ||
| 387 | X509_free(*cert); | ||
| 388 | *cert = NULL; | ||
| 389 | } | ||
| 371 | X509_NAME_free(subject); | 390 | X509_NAME_free(subject); |
| 372 | return ret; | 391 | return ret; |
| 373 | } | 392 | } |
| @@ -395,6 +414,9 @@ int ff_ssl_gen_key_cert(char *key_buf, size_t key_sz, char *cert_buf, size_t cer · 21 unmodified lines | |||
| 395 | av_free(key_tem); | 414 | av_free(key_tem); |
| 396 | av_free(cert_tem); | 415 | av_free(cert_tem); |
| 397 | error: | 416 | error: |
| 417 | X509_free(cert); | ||
| 418 | EC_KEY_free(ec_key); | ||
| 419 | EVP_PKEY_free(pkey); | ||
| 398 | return ret; | 420 | return ret; |
| 399 | } | 421 | } |
| 400 | 422 | ||