Skip to content

Commit

Permalink
unnecessarily high string array allocations used in ITypeInfo::GetNames
Browse files Browse the repository at this point in the history
missing ITypeLib::ReleaseTLibAttr
  • Loading branch information
WaynePhillipsEA committed Jan 14, 2018
1 parent 4a6db52 commit b52e0d9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Rubberduck.Parsing/ComReflection/ComEnumerationMember.cs
Expand Up @@ -18,7 +18,7 @@ public ComEnumerationMember(ITypeInfo info, VARDESC varDesc)
Value = (int)value.Value;
ValueType = value.VariantType;

var names = new string[255];
var names = new string[1];
int count;
info.GetNames(varDesc.memid, names, 1, out count);
Debug.Assert(count == 1);
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/ComReflection/ComModule.cs
Expand Up @@ -52,14 +52,14 @@ public ComModule(ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index) :

private void GetComFields(ITypeInfo info, TYPEATTR attrib)
{
var names = new string[255];
var names = new string[1];
for (var index = 0; index < attrib.cVars; index++)
{
IntPtr varPtr;
info.GetVarDesc(index, out varPtr);
var desc = (VARDESC)Marshal.PtrToStructure(varPtr, typeof(VARDESC));
int length;
info.GetNames(desc.memid, names, 255, out length);
info.GetNames(desc.memid, names, 1, out length);
Debug.Assert(length == 1);

_fields.Add(new ComField(names[0], desc, index, DeclarationType.Constant));
Expand Down
2 changes: 2 additions & 0 deletions Rubberduck.Parsing/ComReflection/ComProject.cs
Expand Up @@ -93,6 +93,8 @@ private void ProcessLibraryAttributes(ITypeLib typeLibrary)
MinorVersion = typeAttr.wMinorVerNum;
_flags = (TypeLibTypeFlags)typeAttr.wLibFlags;
Guid = typeAttr.guid;

typeLibrary.ReleaseTLibAttr(attribPtr);
}
catch (COMException) { }
}
Expand Down
4 changes: 2 additions & 2 deletions Rubberduck.Parsing/ComReflection/ComStruct.cs
Expand Up @@ -27,14 +27,14 @@ public ComStruct(ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index)

private void GetFields(ITypeInfo info, TYPEATTR attrib)
{
var names = new string[255];
var names = new string[1];
for (var index = 0; index < attrib.cVars; index++)
{
IntPtr varPtr;
info.GetVarDesc(index, out varPtr);
var desc = (VARDESC)Marshal.PtrToStructure(varPtr, typeof(VARDESC));
int length;
info.GetNames(desc.memid, names, 255, out length);
info.GetNames(desc.memid, names, 1, out length);
Debug.Assert(length == 1);

_fields.Add(new ComField(names[0], desc, index, DeclarationType.UserDefinedTypeMember));
Expand Down

0 comments on commit b52e0d9

Please sign in to comment.