diff --git a/compiler/pdecl.pas b/compiler/pdecl.pas index a2735db724..d7613ea32d 100644 --- a/compiler/pdecl.pas +++ b/compiler/pdecl.pas @@ -1040,6 +1040,7 @@ implementation begin add_synthetic_rtti_function_declarations(rtti_attrs_def,hdef.typesym.Name); tobjectdef(hdef).rtti_attribute_list:=rtti_attrs_def; + rtti_attrs_def.is_bound:=true; rtti_attrs_def := nil; end; diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 7d8769910f..b1109cc0db 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -218,6 +218,7 @@ implementation begin add_synthetic_rtti_function_declarations(rtti_attrs_def,current_structdef.RttiName+'_'+p.RealName); p.rtti_attribute_list := rtti_attrs_def; + p.rtti_attribute_list.is_bound:=true; rtti_attrs_def:=nil; end; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 30e586ead3..08277be555 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -70,6 +70,8 @@ interface trtti_attribute_list = class rtti_attributes : TFPObjectList; + { if the attribute list is bound to a def or symbol } + is_bound : Boolean; procedure addattribute(atypesym:tsym;constructorcall:tnode;constref paras:array of tnode); destructor destroy; override; function get_attribute_count:longint; @@ -2919,7 +2921,14 @@ implementation end; destructor trtti_attribute_list.destroy; + var + i : longint; begin + { if the attributes are not bound we need to free their generated + constructor functions as well } + if not is_bound and assigned(rtti_attributes) then + for i:=0 to rtti_attributes.count-1 do + trtti_attribute(rtti_attributes[i]).constructorcall.free; rtti_attributes.Free; inherited destroy; end;