@@ -239,9 +239,11 @@ static const PyConfigSpec PYPRECONFIG_SPEC[] = {
239
239
240
240
241
241
// Forward declarations
242
- static PyObject *
243
- config_get (const PyConfig * config , const PyConfigSpec * spec ,
244
- int use_sys );
242
+ static PyObject * config_get (const PyConfig * config , const PyConfigSpec * spec ,
243
+ int use_sys );
244
+ static void initconfig_free_wstr (wchar_t * member );
245
+ static void initconfig_free_wstr_list (PyWideStringList * list );
246
+ static void initconfig_free_config (const PyConfig * config );
245
247
246
248
247
249
/* --- Command line options --------------------------------------- */
@@ -3725,6 +3727,8 @@ PyInitConfig_Free(PyInitConfig *config)
3725
3727
if (config == NULL ) {
3726
3728
return ;
3727
3729
}
3730
+
3731
+ initconfig_free_config (& config -> config );
3728
3732
free (config -> err_msg );
3729
3733
free (config );
3730
3734
}
@@ -4093,13 +4097,51 @@ PyInitConfig_SetStr(PyInitConfig *config, const char *name, const char* value)
4093
4097
}
4094
4098
4095
4099
4100
+ static void
4101
+ initconfig_free_wstr (wchar_t * member )
4102
+ {
4103
+ if (member ) {
4104
+ free (member );
4105
+ }
4106
+ }
4107
+
4108
+
4109
+ static void
4110
+ initconfig_free_wstr_list (PyWideStringList * list )
4111
+ {
4112
+ for (Py_ssize_t i = 0 ; i < list -> length ; i ++ ) {
4113
+ free (list -> items [i ]);
4114
+ }
4115
+ free (list -> items );
4116
+ }
4117
+
4118
+
4119
+ static void
4120
+ initconfig_free_config (const PyConfig * config )
4121
+ {
4122
+ const PyConfigSpec * spec = PYCONFIG_SPEC ;
4123
+ for (; spec -> name != NULL ; spec ++ ) {
4124
+ void * member = config_get_spec_member (config , spec );
4125
+ if (spec -> type == PyConfig_MEMBER_WSTR
4126
+ || spec -> type == PyConfig_MEMBER_WSTR_OPT )
4127
+ {
4128
+ wchar_t * wstr = * (wchar_t * * )member ;
4129
+ initconfig_free_wstr (wstr );
4130
+ }
4131
+ else if (spec -> type == PyConfig_MEMBER_WSTR_LIST ) {
4132
+ initconfig_free_wstr_list (member );
4133
+ }
4134
+ }
4135
+ }
4136
+
4137
+
4096
4138
static int
4097
- _PyWideStringList_FromUTF8 (PyInitConfig * config , PyWideStringList * list ,
4098
- Py_ssize_t length , char * const * items )
4139
+ initconfig_set_str_list (PyInitConfig * config , PyWideStringList * list ,
4140
+ Py_ssize_t length , char * const * items )
4099
4141
{
4100
4142
PyWideStringList wlist = _PyWideStringList_INIT ;
4101
4143
size_t size = sizeof (wchar_t * ) * length ;
4102
- wlist .items = (wchar_t * * )PyMem_RawMalloc (size );
4144
+ wlist .items = (wchar_t * * )malloc (size );
4103
4145
if (wlist .items == NULL ) {
4104
4146
config -> status = _PyStatus_NO_MEMORY ();
4105
4147
return -1 ;
@@ -4108,14 +4150,14 @@ _PyWideStringList_FromUTF8(PyInitConfig *config, PyWideStringList *list,
4108
4150
for (Py_ssize_t i = 0 ; i < length ; i ++ ) {
4109
4151
wchar_t * arg = utf8_to_wstr (config , items [i ]);
4110
4152
if (arg == NULL ) {
4111
- _PyWideStringList_Clear (& wlist );
4153
+ initconfig_free_wstr_list (& wlist );
4112
4154
return -1 ;
4113
4155
}
4114
4156
wlist .items [i ] = arg ;
4115
4157
wlist .length ++ ;
4116
4158
}
4117
4159
4118
- _PyWideStringList_Clear (list );
4160
+ initconfig_free_wstr_list (list );
4119
4161
* list = wlist ;
4120
4162
return 0 ;
4121
4163
}
@@ -4136,7 +4178,7 @@ PyInitConfig_SetStrList(PyInitConfig *config, const char *name,
4136
4178
return -1 ;
4137
4179
}
4138
4180
PyWideStringList * list = raw_member ;
4139
- if (_PyWideStringList_FromUTF8 (config , list , length , items ) < 0 ) {
4181
+ if (initconfig_set_str_list (config , list , length , items ) < 0 ) {
4140
4182
return -1 ;
4141
4183
}
4142
4184
0 commit comments