From 4251a64fec8556bae563c01edf6cde38b9d03610 Mon Sep 17 00:00:00 2001 From: inoussa Date: Wed, 24 Feb 2010 16:34:06 +0000 Subject: [PATCH] Fix mem leak in GetServiceDefaultAddress and GetServiceDefaultFormatProperties git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1165 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- wst/trunk/metadata_repository.pas | 46 +++++++++++++++++++------------ 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/wst/trunk/metadata_repository.pas b/wst/trunk/metadata_repository.pas index 3a1e50221..e04d639de 100644 --- a/wst/trunk/metadata_repository.pas +++ b/wst/trunk/metadata_repository.pas @@ -124,16 +124,22 @@ var typData : PTypeData; servcMdt : PService; propData : PPropertyData; + mmm : IModuleMetadataMngr; begin Result := ''; if Assigned(AServiceTyp) and (AServiceTyp^.Kind = tkInterface) then begin typData := GetTypeData(AServiceTyp); if Assigned(typData) then begin - servcMdt := GetModuleMetadataMngr().GetServiceMetadata(typData^.IntfUnit,AServiceTyp^.Name); - if Assigned(AServiceTyp) then begin - propData := Find(servcMdt^.Properties,sTRANSPORT + '_' + sADDRESS); - if Assigned(propData) then - Result := propData^.Data; + mmm := GetModuleMetadataMngr(); + servcMdt := mmm.GetServiceMetadata(typData^.IntfUnit,AServiceTyp^.Name); + if Assigned(servcMdt) then begin + try + propData := Find(servcMdt^.Properties,sTRANSPORT + '_' + sADDRESS); + if Assigned(propData) then + Result := propData^.Data; + finally + mmm.ClearServiceMetadata(servcMdt); + end; end; end; end; @@ -145,25 +151,31 @@ var servcMdt : PService; propData : PPropertyData; strName : string; + mmm : IModuleMetadataMngr; begin Result := ''; if Assigned(AServiceTyp) and (AServiceTyp^.Kind = tkInterface) then begin typData := GetTypeData(AServiceTyp); if Assigned(typData) then begin - servcMdt := GetModuleMetadataMngr().GetServiceMetadata(typData^.IntfUnit,AServiceTyp^.Name); - if Assigned(AServiceTyp) then begin - propData := servcMdt^.Properties; - while Assigned(propData) do begin - if ( AnsiPos(sFORMAT + '_',propData^.Name) = 1 ) then begin - strName := ExtractOptionName(propData^.Name); - if ( Length(strName) > 0 ) then begin - Result := Format('%s%s=%s;',[Result,strName,propData^.Data]); + mmm := GetModuleMetadataMngr(); + servcMdt := mmm.GetServiceMetadata(typData^.IntfUnit,AServiceTyp^.Name); + if Assigned(servcMdt) then begin + try + propData := servcMdt^.Properties; + while Assigned(propData) do begin + if ( AnsiPos(sFORMAT + '_',propData^.Name) = 1 ) then begin + strName := ExtractOptionName(propData^.Name); + if ( Length(strName) > 0 ) then begin + Result := Format('%s%s=%s;',[Result,strName,propData^.Data]); + end; end; + propData := propData^.Next; end; - propData := propData^.Next; - end; - if not IsStrEmpty(Result) then begin - Delete(Result,Length(Result),1); + if not IsStrEmpty(Result) then begin + Delete(Result,Length(Result),1); + end; + finally + mmm.ClearServiceMetadata(servcMdt); end; end; end;