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 | 161 | int ret = 0; |
| 162 | 162 | BIO *key_b = NULL, *cert_b = NULL; |
| 163 | 163 | AVBPrint key_bp, cert_bp; |
| 164 | − EVP_PKEY *pkey; | |
| 165 | − X509 *cert; | |
| 164 | + EVP_PKEY *pkey = NULL; | |
| 165 | + X509 *cert = NULL; | |
| 166 | 166 | char *key_tem = NULL, *cert_tem = NULL; |
| 167 | 167 | |
| 168 | 168 | /* To prevent a crash during cleanup, always initialize it. */ |
| @@ -230,6 +230,8 @@ end: · 61 unmodified lines | ||
| 230 | 230 | av_bprint_finalize(&cert_bp, NULL); |
| 231 | 231 | av_free(key_tem); |
| 232 | 232 | av_free(cert_tem); |
| 233 | + EVP_PKEY_free(pkey); | |
| 234 | + X509_free(cert); | |
| 233 | 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 | 258 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ |
| 257 | 259 | *pkey = EVP_PKEY_new(); |
| 260 | + if (!*pkey) | |
| 261 | + return AVERROR(ENOMEM); | |
| 262 | + | |
| 258 | 263 | *eckey = EC_KEY_new(); |
| 264 | + if (!*eckey) { | |
| 265 | + EVP_PKEY_free(*pkey); | |
| 266 | + *pkey = NULL; | |
| 267 | + return AVERROR(ENOMEM); | |
| 268 | + } | |
| 269 | + | |
| 259 | 270 | ecgroup = EC_GROUP_new_by_curve_name(curve); |
| 260 | 271 | if (!ecgroup) { |
| 261 | 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 | 299 | einval_end: |
| 289 | 300 | ret = AVERROR(EINVAL); |
| 301 | + EC_KEY_free(*eckey); | |
| 302 | + EVP_PKEY_free(*pkey); | |
| 303 | + *eckey = NULL; | |
| 304 | + *pkey = NULL; | |
| 290 | 305 | end: |
| 291 | 306 | #if OPENSSL_VERSION_NUMBER < 0x30000000L /* OpenSSL 3.0 */ |
| 292 | 307 | EC_GROUP_free(ecgroup); |
| @@ -368,6 +383,10 @@ enomem_end: · 75 unmodified lines | ||
| 368 | 383 | einval_end: |
| 369 | 384 | ret = AVERROR(EINVAL); |
| 370 | 385 | end: |
| 386 | + if (ret) { | |
| 387 | + X509_free(*cert); | |
| 388 | + *cert = NULL; | |
| 389 | + } | |
| 371 | 390 | X509_NAME_free(subject); |
| 372 | 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 | 414 | av_free(key_tem); |
| 396 | 415 | av_free(cert_tem); |
| 397 | 416 | error: |
| 417 | + X509_free(cert); | |
| 418 | + EC_KEY_free(ec_key); | |
| 419 | + EVP_PKEY_free(pkey); | |
| 398 | 420 | return ret; |
| 399 | 421 | } |
| 400 | 422 | |