Browse Source

* ensure that FLock is released in case of an exception

git-svn-id: trunk@37385 -
svenbarth 7 years ago
parent
commit
794eb7c122
1 changed files with 36 additions and 30 deletions
  1. 36 30
      packages/rtl-objpas/src/inc/rtti.pp

+ 36 - 30
packages/rtl-objpas/src/inc/rtti.pp

@@ -619,10 +619,13 @@ begin
     Exit(Nil);
 {$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalsection(FLock);
+  try
 {$endif}
-  Result := Copy(FTypesList, 0, FTypeCount);
+    Result := Copy(FTypesList, 0, FTypeCount);
 {$ifdef FPC_HAS_FEATURE_THREADING}
-  LeaveCriticalsection(FLock);
+  finally
+    LeaveCriticalsection(FLock);
+  end;
 {$endif}
 end;
 
@@ -634,38 +637,41 @@ begin
     Exit(Nil);
 {$ifdef FPC_HAS_FEATURE_THREADING}
   EnterCriticalsection(FLock);
+  try
 {$endif}
-  Result := Nil;
-  for i := 0 to FTypeCount - 1 do
-    begin
-      if FTypesList[i].FTypeInfo = ATypeInfo then
-        begin
-          Result := FTypesList[i];
-          Break;
-        end;
-    end;
-  if not Assigned(Result) then
-    begin
-      if FTypeCount = Length(FTypesList) then
-        begin
-          SetLength(FTypesList, FTypeCount * 2);
+    Result := Nil;
+    for i := 0 to FTypeCount - 1 do
+      begin
+        if FTypesList[i].FTypeInfo = ATypeInfo then
+          begin
+            Result := FTypesList[i];
+            Break;
+          end;
+      end;
+    if not Assigned(Result) then
+      begin
+        if FTypeCount = Length(FTypesList) then
+          begin
+            SetLength(FTypesList, FTypeCount * 2);
+          end;
+        case ATypeInfo^.Kind of
+          tkClass   : Result := TRttiInstanceType.Create(ATypeInfo);
+          tkSString,
+          tkLString,
+          tkAString,
+          tkUString,
+          tkWString : Result := TRttiStringType.Create(ATypeInfo);
+          tkFloat   : Result := TRttiFloatType.Create(ATypeInfo);
+        else
+          Result := TRttiType.Create(ATypeInfo);
         end;
-      case ATypeInfo^.Kind of
-        tkClass   : Result := TRttiInstanceType.Create(ATypeInfo);
-        tkSString,
-        tkLString,
-        tkAString,
-        tkUString,
-        tkWString : Result := TRttiStringType.Create(ATypeInfo);
-        tkFloat   : Result := TRttiFloatType.Create(ATypeInfo);
-      else
-        Result := TRttiType.Create(ATypeInfo);
+        FTypesList[FTypeCount] := Result;
+        Inc(FTypeCount);
       end;
-      FTypesList[FTypeCount] := Result;
-      Inc(FTypeCount);
-    end;
 {$ifdef FPC_HAS_FEATURE_THREADING}
-  LeaveCriticalsection(FLock);
+  finally
+    LeaveCriticalsection(FLock);
+  end;
 {$endif}
 end;