Skip to content

Commit 9f13436

Browse files
miss-islingtonjelle-openaiJelleZijlstra
authored
[3.15] gh-159739: Release replaced PyInitConfig strings (GH-159769) (#159809)
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 240e705 commit 9f13436

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
@@ -4357,14 +4357,17 @@ PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char* value)
43574357

43584358
if (value == NULL && spec->type != PyConfig_MEMBER_WSTR_OPT) {
43594359
initconfig_set_error(config, "config option string cannot be NULL");
4360+
return -1;
43604361
}
43614362

43624363
wchar_t **member = raw_member;
43634364

4364-
*member = utf8_to_wstr(config, value);
4365-
if (*member == NULL) {
4365+
wchar_t *wstr = utf8_to_wstr(config, value);
4366+
if (wstr == NULL) {
43664367
return -1;
43674368
}
4369+
free(*member);
4370+
*member = wstr;
43684371
return 0;
43694372
}
43704373

0 commit comments

Comments
 (0)