diff --git a/php/ext/google/protobuf/names.c b/php/ext/google/protobuf/names.c index 73e28186e3..e359d01728 100644 --- a/php/ext/google/protobuf/names.c +++ b/php/ext/google/protobuf/names.c @@ -275,10 +275,8 @@ bool IsPreviouslyUnreservedClassName(const char* fullname) { } classname += 2; int length = strlen(classname); - char* lower =strdup_nolocale_lower(classname, length); - - int j; - for (j = 0; kPreviouslyUnreservedNames[j]; j++) { + char* lower = strdup_nolocale_lower(classname, length); + for (int j = 0; kPreviouslyUnreservedNames[j]; j++) { if (strcmp(kPreviouslyUnreservedNames[j], lower) == 0) { free(lower); return true; diff --git a/php/ext/google/protobuf/protobuf.c b/php/ext/google/protobuf/protobuf.c index a401d211c3..a5aba23f47 100644 --- a/php/ext/google/protobuf/protobuf.c +++ b/php/ext/google/protobuf/protobuf.c @@ -246,8 +246,10 @@ void NameMap_AddMessage(const upb_MessageDef *m) { char *k = GetPhpClassname(upb_MessageDef_File(m), upb_MessageDef_FullName(m), (bool)i); zend_hash_str_add_ptr(&PROTOBUF_G(name_msg_cache), k, strlen(k), (void*)m); if (!IsPreviouslyUnreservedClassName(k)) { + free(k); return; } + free(k); } }