Memory Leak and MultiThreading Problem in TRORttiClientCache.GetCustomAttributes

delphi
rttisupport

(Alexander Pustotin) #1

Hi

I use RO SDK

const
  RO_VERSION = '9.5.111.1399';

We found two problems in TRORttiClientCache.GetCustomAttributes:

  • memory leak
  • non-threadsafe code

This is a proposed fix:

function TRORttiClientCache.GetCustomAttributes(aObject: TRttiObject): TDictionary<String, String>;
var
  la : TArray<ROCustomAttribute>;
  a: ROCustomAttribute;
begin
  BeginRead;
  try
    if fCustomAttributes.TryGetValue(aObject, result) then
      Exit;
    BeginWrite;
    try
      if not fCustomAttributes.TryGetValue(aObject, result) then begin
        Result := CreateDict<String>;
        la := aObject.ROGetAttributes<ROCustomAttribute>;
        for a in la do
          Result.Add(LowerCase(a.Name), a.Value);
        fCustomAttributes.Add(aObject, result); // <- fixing the leak
      end;
    finally
      EndWrite;
    end;
  finally
    EndRead;
  end;
end;

regards


(RemObjects) #2

Thanks, logged as bugs://82003


(RemObjects) #3

bugs://82003 got closed with status fixed.


(EvgenyK) #4

this fix will be included into next beta