Browse Source

* Fixed resource-leak on exceptions during creating/dropping databases, patch from taka_jp, bug #13587

git-svn-id: trunk@13190 -
joost 16 years ago
parent
commit
d39e82b256
1 changed files with 15 additions and 12 deletions
  1. 15 12
      packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

+ 15 - 12
packages/fcl-db/src/sqldb/mysql/mysqlconn.inc

@@ -310,18 +310,21 @@ begin
 
 
   InitialiseMysql;
   InitialiseMysql;
 
 
-  H:=HostName;
-  U:=UserName;
-  P:=Password;
-  AMySQL := nil;
-  ConnectMySQL(AMySQL,pchar(H),pchar(U),pchar(P));
-
-  if mysql_query(AMySQL,pchar(query))<>0 then
-    MySQLError(AMySQL,Format(SErrExecuting,[StrPas(mysql_error(AMySQL))]),Self);
-
-  mysql_close(AMySQL);
-
-  ReleaseMysql;
+  try
+    H:=HostName;
+    U:=UserName;
+    P:=Password;
+    AMySQL := nil;
+    ConnectMySQL(AMySQL,pchar(H),pchar(U),pchar(P));
+    try
+      if mysql_query(AMySQL,pchar(query))<>0 then
+        MySQLError(AMySQL,Format(SErrExecuting,[StrPas(mysql_error(AMySQL))]),Self);
+    finally
+      mysql_close(AMySQL);
+    end;
+  finally
+    ReleaseMysql;
+  end;
 end;
 end;
 
 
 function TConnectionName.EscapeString(const Str: string): string;
 function TConnectionName.EscapeString(const Str: string): string;