Skip to content

Commit 60eee27

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Avoid potentially superfluous string reallocation
2 parents 287f5cc + 427ebce commit 60eee27

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

ext/com_dotnet/com_typeinfo.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,15 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa
184184
}
185185

186186
const_name = php_com_olestring_to_string(bstr_ids, &len, codepage);
187-
c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT);
188-
// TODO: avoid reallocation???
189-
efree(const_name);
190-
if(c.name == NULL) {
191-
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
192-
continue;
193-
}
194-
//??? c.name_len++; /* include NUL */
195187
SysFreeString(bstr_ids);
196188

197189
/* sanity check for the case where the constant is already defined */
198190
php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage);
199-
if ((exists = zend_get_constant(c.name)) != NULL) {
191+
if ((exists = zend_get_constant_str(const_name, len)) != NULL) {
200192
if (COMG(autoreg_verbose) && !compare_function(&results, &value, exists)) {
201-
php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", ZSTR_VAL(c.name));
193+
php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", const_name);
202194
}
203-
zend_string_release_ex(c.name, mode & CONST_PERSISTENT);
195+
efree(const_name);
204196
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
205197
continue;
206198
}
@@ -209,6 +201,8 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa
209201
if (Z_TYPE(value) == IS_LONG) {
210202
ZEND_CONSTANT_SET_FLAGS(&c, mode, 0);
211203
ZVAL_LONG(&c.value, Z_LVAL(value));
204+
c.name = zend_string_init(const_name, len, mode & CONST_PERSISTENT);
205+
efree(const_name);
212206
zend_register_constant(&c);
213207
}
214208
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);

0 commit comments

Comments
 (0)