Commit 97daefb4d6 for ffmpeg
commit 97daefb4d6775aff6b143dbdb4ad743fe2b3a577
Author: zhang xingxing <2388969553@qq.com>
Date: Tue Oct 13 06:57:02 2026 +0200
avformat/tls_mbedtls: free the mbedtls contexts on every error path
This is not a security issue.
Not replicated, compile tested only (mbedtls 3.6.2).
Fixes: T7EtPuJBKWqg
Fixes: swarm-Memory-leak-early-return-skips-mbedtls-resource-cleanup-a1d295
Found-by: zhang xingxing <2388969553@qq.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
diff --git a/libavformat/tls_mbedtls.c b/libavformat/tls_mbedtls.c
index 444148be8a..211652d38a 100644
--- a/libavformat/tls_mbedtls.c
+++ b/libavformat/tls_mbedtls.c
@@ -186,7 +186,7 @@ static int mbedtls_gen_x509_cert(mbedtls_pk_context *key, char *cert_buf, size_t
ret = av_random_bytes((uint8_t *)serial, sizeof(serial));
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to generate random serial number!\n");
- return ret;
+ goto end;
}
if ((ret = mbedtls_x509write_crt_set_serial_raw(&crt, serial, sizeof(serial))) != 0) {
@@ -208,7 +208,7 @@ static int mbedtls_gen_x509_cert(mbedtls_pk_context *key, char *cert_buf, size_t
if ((ret = mbedtls_x509write_crt_pem(&crt, cert_buf, cert_sz,
mbedtls_ctr_drbg_random, &ctr_drbg)) != 0) {
av_log(NULL, AV_LOG_ERROR, "mbedtls_x509write_crt_pem returned %d\n", ret);
- return ret;
+ goto end;
}
end: