Skip to content

Commit a3fdda2

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.14] gh-159739: Release replaced PyInitConfig strings (GH-159769) (#159810)
gh-159739: Release replaced PyInitConfig strings (GH-159769) * gh-159739: Release replaced PyInitConfig strings Backport to 3.15 and 3.14. --------- (cherry picked from commit 395d766) Co-authored-by: Jelle Zijlstra <jelle@openai.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 84990b5 commit a3fdda2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:c:func:`PyInitConfig_SetStr` now releases a previously configured value and
2+
preserves it if conversion of the replacement fails.

‎Python/initconfig.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,14 +4135,17 @@ PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char* value)
41354135

41364136
if (value == NULL && spec->type != PyConfig_MEMBER_WSTR_OPT) {
41374137
initconfig_set_error(config, "config option string cannot be NULL");
4138+
return -1;
41384139
}
41394140

41404141
wchar_t **member = raw_member;
41414142

4142-
*member = utf8_to_wstr(config, value);
4143-
if (*member == NULL) {
4143+
wchar_t *wstr = utf8_to_wstr(config, value);
4144+
if (wstr == NULL) {
41444145
return -1;
41454146
}
4147+
free(*member);
4148+
*member = wstr;
41464149
return 0;
41474150
}
41484151

0 commit comments

Comments
 (0)