From: Sean Bright Date: Wed, 25 Oct 2023 22:19:13 +0000 (-0400) Subject: res_rtp_asterisk.c: Fix memory leak in ephemeral certificate creation. X-Git-Tag: 18.21.0-rc1~52 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a30ec962cbcbbff67b151a857b6223fb1e4cab0;p=thirdparty%2Fasterisk.git res_rtp_asterisk.c: Fix memory leak in ephemeral certificate creation. Fixes #386 (cherry picked from commit 2aa6a63188c7c46c032887053814a33cf7514076) --- diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 8bfa2711b8..c641641bbf 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -2029,9 +2029,12 @@ static int create_ephemeral_certificate(EVP_PKEY *keypair, X509 **certificate) if (!(serial = BN_new()) || !BN_rand(serial, SERIAL_RAND_BITS, -1, 0) || !BN_to_ASN1_INTEGER(serial, X509_get_serialNumber(cert))) { + BN_free(serial); goto error; } + BN_free(serial); + /* * Validity period - Current Chrome & Firefox make it 31 days starting * with yesterday at the current time, so we will do the same. @@ -2066,7 +2069,6 @@ static int create_ephemeral_certificate(EVP_PKEY *keypair, X509 **certificate) return 0; error: - BN_free(serial); X509_free(cert); return -1;