From 546dddca43a2a69dbe33d230e9e540636b403270 Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Tue, 15 Oct 2024 17:21:16 +0800 Subject: [PATCH] gh-125234: Make PyInitConfig_Free(NULL) a no-op (#125266) --- Doc/c-api/init_config.rst | 2 ++ Programs/_testembed.c | 1 + Python/initconfig.c | 3 +++ 3 files changed, 6 insertions(+) diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst index 6f8962afc7a..66e845df2e6 100644 --- a/Doc/c-api/init_config.rst +++ b/Doc/c-api/init_config.rst @@ -1621,6 +1621,8 @@ Create Config Free memory of the initialization configuration *config*. + If *config* is ``NULL``, no operation is performed. + Error Handling -------------- diff --git a/Programs/_testembed.c b/Programs/_testembed.c index ab619e32429..0fb45b2265e 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1896,6 +1896,7 @@ static int test_initconfig_api(void) goto error; } PyInitConfig_Free(config); + PyInitConfig_Free(NULL); dump_config(); Py_Finalize(); diff --git a/Python/initconfig.c b/Python/initconfig.c index 58ac5e7d7ea..c142438b02b 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -3457,6 +3457,9 @@ PyInitConfig_Create(void) void PyInitConfig_Free(PyInitConfig *config) { + if (config == NULL) { + return; + } free(config->err_msg); free(config); }