diff --git a/source/childwin.pas b/source/childwin.pas index 88299d19..dddd47ba 100644 --- a/source/childwin.pas +++ b/source/childwin.pas @@ -1126,15 +1126,33 @@ procedure TMDIChild.FormClose(Sender: TObject; var Action: TCloseAction); var ws : String; reg : TRegistry; + ds : TDataSet; begin SetWindowConnected( false ); SetWindowName( main.discname ); Application.Title := APPNAME; + + ds := DataSource1.DataSet; + DataSource1.DataSet := nil; + if ds <> nil then ds.Close; + FreeAndNil(ds); + ds := DataSource2.DataSet; + DataSource2.DataSet := nil; + if ds <> nil then ds.Close; + FreeAndNil(ds); + ClearAllTableLists; + FreeAndNil(CachedTableLists); + FreeAndNil(methodStack); + + // Closing connection + FMysqlConn.Disconnect; + FreeAndNil(FMysqlConn); + EnterCriticalSection(SqlMessagesLock); FreeAndNil(SqlMessages); LeaveCriticalSection(SqlMessagesLock); - // Closing connection and saving some vars into registry + // Saving some vars into registry case ( WindowState ) of wsNormal : begin @@ -1332,6 +1350,8 @@ begin else OnlyDBs2.Add( dbName ); ds.Next(); end; + ds.Close; + FreeAndNil(ds); OnlyDBs2.Sort(); // Prioritised position of system-databases for i := ( specialDbs.Count - 1 ) downto 0 do begin @@ -1543,9 +1563,9 @@ var RewriteOrderClause : Boolean; begin viewingdata := true; + reg := TRegistry.Create(); + sl_query := TStringList.Create(); try - sl_query := TStringList.Create(); - // limit number of rows automatically if first time this table is shown if ( not dataselected ) then begin manualLimit := false; @@ -1557,6 +1577,7 @@ begin if Valueexists('DataLimit') then manualLimit := ReadBool('DataLimit'); end; end; + Free; end; // limit number of rows fetched according to preferences @@ -1590,7 +1611,6 @@ begin EDBImage1.DataField := ''; EDBImage1.DataSource := DataSource1; - reg := TRegistry.Create(); reg.OpenKey( REGPATH + '\Servers\' + FConn.Description, true ); if not dataselected and prefRememberFilters then @@ -1745,6 +1765,7 @@ begin // free previous resultset tmp := DataSource1.DataSet; DataSource1.DataSet := nil; + if tmp <> nil then tmp.Close; FreeAndNil(tmp); // start query (with wait dialog) @@ -1851,8 +1872,9 @@ begin end; Screen.Cursor := crDefault; - FreeAndNil (sl_query); finally + FreeAndNil(reg); + FreeAndNil(sl_query); viewingdata := false; end; end; @@ -2082,11 +2104,12 @@ end; procedure TMDIChild.ClearAllTableLists; var idx: Integer; - o: TObject; + ds: TDataSet; begin for idx := 0 to CachedTableLists.Count - 1 do begin - o := CachedTableLists.Objects[idx]; - FreeAndNil(o); + ds := TDataSet(CachedTableLists.Objects[idx]); + ds.Close; + FreeAndNil(ds); end; CachedTableLists.Clear; end; @@ -2389,6 +2412,8 @@ begin end; end; *} + ds.Close; + FreeAndNil(ds); Screen.Cursor := crHourglass; ds := GetResults( 'SHOW KEYS FROM ' + mask(table) ); @@ -2428,6 +2453,8 @@ begin end; ds.Next; end; + ds.Close; + FreeAndNil(ds); { ** note, ansgarbecker, 2007-08-26 VT has a pretty autosorting feature, which keeps the sorting even after having @@ -2560,17 +2587,9 @@ begin } inDataOrQueryTab := FrmIsFocussed and ((PageControlMain.ActivePage = tabData) or (PageControlMain.ActivePage = tabQuery)); PrintList.Enabled := (not inDataOrQueryTab) and FrmIsFocussed; - {*** - @note ansgarbecker, 2007-31-03 - 1. For data-tab-queries (threaded queries) the TDatasource does *not* have - an linked TDataset/TZquery in case of a SQL-error. To avoid an AV with - NIL-reference we have to first check if the Dataset is existant - if not, - assume the datagrid is empty. - 2. For query-tab-queries (not threaded) the TZQuery is linked - to the TDatasource and we can safely ask for TDataset.IsEmpty without - causing a NIL-reference. - @todo use the same threaded process for both datagrid and query-grid - } + // Both the Query and the Data grid may have a nil DataSet reference, + // either in case the relevant grid has not been used yet, or when + // an error has occurred. inDataOrQueryTabNotEmpty := inDataOrQueryTab and not ( (getActiveGrid.DataSource.DataSet = nil) @@ -2690,6 +2709,7 @@ begin WriteString( 'OnlyDBs', ImplodeStr( ';', OnlyDBs ) ); CloseKey; end; + Free; end; end; end; @@ -2759,6 +2779,8 @@ begin VTRowDataListVariables[i-1].Captions.Add( ds.Fields[1].AsString ); ds.Next; end; + ds.Close; + FreeAndNil(ds); // STATUS uptime := 1; // avoids division by zero :) @@ -2802,6 +2824,8 @@ begin end; ds.Next; end; + ds.Close; + FreeAndNil(ds); // Tell VirtualTree the number of nodes it will display ListCommandStats.RootNodeCount := Length(VTRowDataListCommandStats); @@ -2846,6 +2870,7 @@ begin ds.Next; end; ds.Close; + FreeAndNil(ds); tabProcessList.Caption := 'Process-List (' + IntToStr(Length(VTRowDataListProcesses)) + ')'; except on E: Exception do begin @@ -2933,6 +2958,7 @@ begin // Destroy old data set. ds := DataSource2.DataSet; DataSource2.DataSet := nil; + if ds <> nil then ds.Close; FreeAndNil( ds ); // set db-aware-component's properties.. DBMemo1.DataField := EmptyStr; @@ -3059,11 +3085,6 @@ begin end; end; end; - end - else - begin - // Avoid AV for mousewheel-scrolling in empty datagrid - DataSource2.DataSet := nil; end; // Ensure controls are in a valid state ValidateControls(); @@ -3208,6 +3229,8 @@ var SynCompletionProposal1.ItemList.Add( '\hspace{2}\color{'+ColorToString(clTeal)+'}column\color{clWindowText}\column{}' + ds.FieldByName( 'Field' ).AsString + '\style{-B} ' + ds.FieldByName( 'Type' ).AsString ); ds.Next; end; + ds.Close; + FreeAndNil(ds); end; begin @@ -3476,6 +3499,7 @@ begin WriteString( 'OnlyDBs', ImplodeStr( ';', OnlyDBs ) ); CloseKey; end; + Free; end; end; // Todo: Don't expand node of old database in dbtree, just reload and switch to new one @@ -3833,6 +3857,7 @@ begin reg.DeleteValue( reg_value ); end; reg.CloseKey; + FreeAndNil(reg); ViewData(self); @@ -4200,6 +4225,7 @@ begin popupFilterOpenFile.Items.Add(menuitem); Inc( i ); end; + Free; end; end; @@ -5153,6 +5179,7 @@ end; function TMDIChild.ExecUpdateQuery(sql: string; HandleErrors: Boolean = false; DisplayErrors: Boolean = false): Int64; var MysqlQuery : TMysqlQuery; + ds: TDataSet; begin Result := -1; // Silence compiler warning. MysqlQuery := nil; @@ -5178,7 +5205,13 @@ begin end; finally // Cleanup the MysqlQuery object, we won't need it anymore - if MysqlQuery <> nil then FreeAndNil (MysqlQuery); + if MysqlQuery <> nil then begin + if MysqlQuery.MysqlDataset <> nil then + MysqlQuery.MysqlDataset.Close; + ds := MysqlQuery.MysqlDataset; + FreeAndNil(ds); + end; + FreeAndNil (MysqlQuery); end; end; @@ -5196,23 +5229,27 @@ var res: TMysqlQuery; begin res := nil; + result := nil; try - // Start query execution - res := RunThreadedQuery(sql); - result := res.MysqlDataset; - // Inspect query result code and log / notify user on failure - if res.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then - begin - raise Exception.Create(res.Comment); - end; - except - on E: Exception do begin - LogSQL( E.Message, True ); - if DisplayErrors then MessageDlg( E.Message, mtError, [mbOK], 0 ); - if res <> nil then FreeAndNil(res); - if not HandleErrors then raise THandledSQLError.Create(E.Message); - Result := nil; + try + // Start query execution + res := RunThreadedQuery(sql); + result := res.MysqlDataset; + // Inspect query result code and log / notify user on failure + if res.Result in [MQR_CONNECT_FAIL,MQR_QUERY_FAIL] then + begin + raise Exception.Create(res.Comment); + end; + except + on E: Exception do begin + LogSQL( E.Message, True ); + if DisplayErrors then MessageDlg( E.Message, mtError, [mbOK], 0 ); + if not HandleErrors then raise THandledSQLError.Create(E.Message); + Result := nil; + end; end; + finally + FreeAndNil(res); end; end; @@ -5237,6 +5274,7 @@ begin if ds = nil then exit; Result := ds.Fields[x].AsString; ds.Close; + FreeAndNil(ds); end; @@ -5248,6 +5286,7 @@ begin if ds = nil then exit; Result := ds.Fields.FieldByName(x).AsString; ds.Close; + FreeAndNil(ds); end; {*** @@ -5289,6 +5328,7 @@ begin ds.Next; end; ds.Close; + FreeAndNil(ds); end; @@ -5751,6 +5791,8 @@ begin result := (Trunc(result / ROUNDING) + 1) * ROUNDING; if result >= RecordCount then result := -1; end; + ds.Close; + FreeAndNil(ds); finally debug( 'GetCalculatedLimit: ' + formatnumber(result) ); end; @@ -5979,6 +6021,10 @@ begin sql_default + sql_extra; + // Cleanup + def.Close; + FreeAndNil(def); + // Fire ALTER query ExecUpdateQuery( sql_update, False, False ); @@ -6466,7 +6512,7 @@ begin reg.WriteString( REGPREFIX_COLWIDTHS + List.Name, ColWidths ); reg.WriteString( REGPREFIX_COLSVISIBLE + List.Name, ColsVisible ); reg.WriteString( REGPREFIX_COLPOS + List.Name, ColPos ); - + FreeAndNil(reg); end; diff --git a/source/column_selection.pas b/source/column_selection.pas index 7faddae1..324d1e28 100644 --- a/source/column_selection.pas +++ b/source/column_selection.pas @@ -74,6 +74,7 @@ begin chkSort.Checked := reg.ReadBool(REGNAME_SORTDISPLAYEDCOLUMNS); reg.CloseKey; + FreeAndNil(reg); end; @@ -135,6 +136,7 @@ begin reg.WriteBool( REGNAME_SORTDISPLAYEDCOLUMNS, chkSort.checked ); reg.CloseKey; + FreeAndNil(reg); // Signalizes childwin to refresh grid-data if reg_oldvalue <> reg_newvalue then diff --git a/source/connections.pas b/source/connections.pas index 74858b4a..076df0c1 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -134,6 +134,7 @@ begin if OpenKey(REGPATH, true) then WriteString('lastcon', ComboBoxDescription.Text); CloseKey; + Free; end; mysqlconn := TMysqlConn.Create(@cp); @@ -192,6 +193,7 @@ begin else AutoReconnect := false; CloseKey; + Free; end; if ComboBoxDescription.Items.Count > 0 then begin @@ -259,6 +261,7 @@ begin WriteBool('OnlyDBsSorted', CheckBoxSorted.Checked); CloseKey; end; + Free; end; ComboBoxDescriptionClick(self); Screen.Cursor := crDefault; @@ -304,6 +307,7 @@ begin WriteBool('OnlyDBsSorted', true); CloseKey; end; + Free; end; EnableDisable(true); @@ -322,6 +326,7 @@ begin begin if not DeleteKey(REGPATH + '\Servers\' + ComboBoxDescription.Text) then MessageDlg('Error while deleting Key from Registry!', mtError, [mbOK], 0); + Free; end; FormShow(self); end; @@ -349,6 +354,7 @@ begin CheckBoxSorted.Checked := false; // for existing connections from older HS-versions always off CloseKey; end; + Free; end; ButtonSave.Enabled := false; ButtonSaveAndConnect.Enabled := ButtonSave.Enabled; @@ -426,6 +432,7 @@ begin except MessageDLG('Error on renaming.', mtError, [mbCancel], 0); end; + Free; end; end; diff --git a/source/copytable.pas b/source/copytable.pas index 71aec532..780f318f 100644 --- a/source/copytable.pas +++ b/source/copytable.pas @@ -146,6 +146,8 @@ begin CheckListBoxFields.Items.Add( ds.Fields[0].AsString ); ds.Next; end; + ds.Close; + FreeAndNil(ds); // select all: for i:=0 to CheckListBoxFields.Items.Count-1 do @@ -235,6 +237,8 @@ begin keylist[which].SubParts.add( zq.FieldByName('Sub_part').AsString ); zq.Next; end; + zq.Close; + FreeAndNil(zq); for k:=0 to high(keylist) do begin if k > 0 then @@ -290,6 +294,8 @@ begin end; zq.Next; end; + zq.Close; + FreeAndNil(zq); Mainform.Childwin.MenuRefreshClick(Self); close; diff --git a/source/createdatabase.dfm b/source/createdatabase.dfm index 0c663943..606b5c57 100644 --- a/source/createdatabase.dfm +++ b/source/createdatabase.dfm @@ -15,6 +15,7 @@ object CreateDatabaseForm: TCreateDatabaseForm Position = poOwnerFormCenter OnClose = FormClose OnCreate = FormCreate + OnDestroy = FormDestroy OnShow = FormShow DesignSize = ( 317 diff --git a/source/createdatabase.pas b/source/createdatabase.pas index e1e0488f..98f35df2 100644 --- a/source/createdatabase.pas +++ b/source/createdatabase.pas @@ -18,6 +18,7 @@ type comboCollation: TComboBox; lblPreview: TLabel; SynMemoPreview: TSynMemo; + procedure FormDestroy(Sender: TObject); procedure btnOKClick(Sender: TObject); procedure comboCharsetChange(Sender: TObject); procedure Modified(Sender: TObject); @@ -52,7 +53,7 @@ var charset: String; begin try - dsCollations := Mainform.Childwin.ExecSelectQuery('SHOW COLLATION'); + dsCollations := Mainform.Childwin.GetResults('SHOW COLLATION'); // Detect servers default charset defaultCharset := Mainform.Childwin.GetVar( 'SHOW VARIABLES LIKE '+esc('character_set_server'), 1 ); except @@ -86,6 +87,12 @@ begin end; +procedure TCreateDatabaseForm.FormDestroy(Sender: TObject); +begin + if dsCollations <> nil then dsCollations.Close; + FreeAndNil(dsCollations); +end; + {** Form gets displayed: Set default values. } diff --git a/source/createtable.dfm b/source/createtable.dfm index f23d471f..e8aede20 100644 --- a/source/createtable.dfm +++ b/source/createtable.dfm @@ -14,6 +14,7 @@ object CreateTableForm: TCreateTableForm OldCreateOrder = False Position = poMainFormCenter OnCreate = FormCreate + OnDestroy = FormDestroy OnShow = FormShow DesignSize = ( 499 diff --git a/source/createtable.pas b/source/createtable.pas index 9a9e0504..a6451b8b 100644 --- a/source/createtable.pas +++ b/source/createtable.pas @@ -54,6 +54,7 @@ type lblCollation: TLabel; comboCharset: TComboBox; comboCollation: TComboBox; + procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); procedure EditTablenameChange(Sender: TObject); procedure ButtonCancelClick(Sender: TObject); @@ -135,7 +136,7 @@ var engineSupport : String; begin try - dsCollations := Mainform.Childwin.ExecSelectQuery('SHOW COLLATION'); + dsCollations := Mainform.Childwin.GetResults('SHOW COLLATION'); // Detect servers default charset defaultCharset := Mainform.Childwin.GetVar( 'SHOW VARIABLES LIKE '+esc('character_set_server'), 1 ); except @@ -163,7 +164,7 @@ begin comboCollation.Enabled := dsCollations <> nil; lblCollation.Enabled := comboCollation.Enabled; - dsEngines := Mainform.Childwin.ExecSelectQuery('SHOW ENGINES', True); + dsEngines := Mainform.Childwin.GetResults('SHOW ENGINES', True); if dsEngines <> nil then begin ComboboxTableType.Style := csDropDownList; // No editing needed @@ -181,10 +182,18 @@ begin dsEngines.Next; end; ComboboxTableType.Items.EndUpdate; + dsEngines.Close; end; + FreeAndNil(dsEngines); end; +procedure TCreateTableForm.FormDestroy(Sender: TObject); +begin + if dsCollations <> nil then dsCollations.Close; + FreeAndNil(dsCollations); +end; + procedure TCreateTableForm.ButtonCancelClick(Sender: TObject); begin ModalResult := mrCancel; diff --git a/source/data_sorting.pas b/source/data_sorting.pas index f59f088f..a47537e5 100644 --- a/source/data_sorting.pas +++ b/source/data_sorting.pas @@ -72,6 +72,7 @@ begin reg_name := 'ORDERCLAUSE_' + Mainform.Childwin.ActiveDatabase + '.' + Mainform.Childwin.SelectedTable; OldOrderClause := reg.ReadString(reg_name); reg.CloseKey; + FreeAndNil(reg); // Create one OrderColumns record for each grid.SortColumn grid := Mainform.Childwin.gridData; @@ -353,6 +354,7 @@ begin reg.OpenKey( REGPATH + '\Servers\' + Mainform.Childwin.Description, true ); reg.WriteString( reg_name, ComposeOrderClause ); reg.CloseKey; + FreeAndNil(reg); end; diff --git a/source/exportsql.pas b/source/exportsql.pas index b99cdb2d..f23da535 100644 --- a/source/exportsql.pas +++ b/source/exportsql.pas @@ -273,6 +273,7 @@ begin end; if ValueExists('ExportSQL_WindowWidth') then Width := ReadInteger('ExportSQL_WindowWidth'); if ValueExists('ExportSQL_WindowHeight') then Height := ReadInteger('ExportSQL_WindowHeight'); + Free; end; if EditFileName.Text = '' then @@ -746,6 +747,8 @@ begin begin Query := cwin.GetResults('SHOW CREATE TABLE ' + sourceMask(checkListTables.Items[i])); sql := Query.Fields[1].AsString; + Query.Close; + FreeAndNil(Query); sql := fixNewlines(sql); if Pos('DEFAULT CHARSET', sql) > 0 then begin Insert('/*!40100 ', sql, Pos('DEFAULT CHARSET', sql)); @@ -812,6 +815,8 @@ begin if j < Query.Fieldcount then sql := sql + ',' + crlf; end; + Query.Close; + FreeAndNil(Query); // Keys: Query := cwin.GetResults( 'SHOW KEYS FROM ' + sourceMask(checkListTables.Items[i])); @@ -850,6 +855,8 @@ begin keylist[which].Columns.add(destMask(Query.Fields[4].AsString)); // add column(s) Query.Next; end; + Query.Close; + FreeAndNil(Query); for k:=0 to high(keylist) do begin if k > 0 then @@ -916,6 +923,8 @@ begin Query.Next; end; columnnames := columnnames+')'; + Query.Close; + FreeAndNil(Query); if tofile then begin @@ -1092,6 +1101,7 @@ begin insertquery := ''; end; Query.Close; + FreeAndNil(Query); end; // Set back to local setting: setLocales; @@ -1463,6 +1473,7 @@ begin WriteInteger('ExportSQL_WindowWidth', Width ); WriteInteger('ExportSQL_WindowHeight', Height ); CloseKey(); + Free; end; end; diff --git a/source/fieldeditor.pas b/source/fieldeditor.pas index 6897798d..f8e5f377 100644 --- a/source/fieldeditor.pas +++ b/source/fieldeditor.pas @@ -261,6 +261,8 @@ begin klist[TempKeys.IndexOf(ds.Fields[2].AsString)].Columns.Add(ds.Fields[4].AsString); ds.Next; end; + ds.Close; + FreeAndNil(ds); listColumnsAvailable.Items := GetVTCaptions(cwin.ListColumns); showkeys(); diff --git a/source/insertfiles.pas b/source/insertfiles.pas index 469f46eb..5f495229 100644 --- a/source/insertfiles.pas +++ b/source/insertfiles.pas @@ -154,6 +154,8 @@ begin cols[length(cols)-1].Quote := false; ds.Next; end; + ds.Close; + FreeAndNil(ds); DisplayColumns(self); end; end; diff --git a/source/insertfiles_progress.pas b/source/insertfiles_progress.pas index 9d4e1f00..a6d2efe4 100644 --- a/source/insertfiles_progress.pas +++ b/source/insertfiles_progress.pas @@ -137,7 +137,7 @@ begin end; FINALLY - zq.ParamCheck := false; + FreeAndNil(zq); screen.Cursor := crDefault; Close(); END; diff --git a/source/loaddata.pas b/source/loaddata.pas index 4c3696b8..b1679167 100644 --- a/source/loaddata.pas +++ b/source/loaddata.pas @@ -145,8 +145,8 @@ begin chkReplace.Checked := reg.ReadBool('CSVImportReplace'); if reg.ValueExists('CSVImportIgnore') then chkIgnore.Checked := reg.ReadBool('CSVImportIgnore'); + Free; end; - end; @@ -186,6 +186,8 @@ begin chklistColumns.Items.Add(ds.Fields[0].AsString); ds.Next; end; + ds.Close; + FreeAndNil(ds); end; // select all: @@ -230,6 +232,7 @@ begin reg.WriteBool( 'CSVImportReplace', chkReplace.Checked ); reg.WriteBool( 'CSVImportIgnore', chkIgnore.Checked ); end; + FreeAndNil(reg); query := 'LOAD DATA '; diff --git a/source/main.pas b/source/main.pas index 9078fcbd..4976ad10 100644 --- a/source/main.pas +++ b/source/main.pas @@ -389,6 +389,7 @@ begin WriteInteger('ToolBarDataTop', ToolBarData.Top); end; CloseKey; + Free; end; GetTempPath(MAX_PATH, buffer); filename := buffer; @@ -446,6 +447,7 @@ begin ToolBarData.Top := ReadInteger('ToolBarDataTop'); end; CloseKey; + Free; end; // Beautify appversion @@ -883,6 +885,7 @@ begin WriteString('CSVEncloser', FieldEncl); WriteString('CSVTerminator', LineSep); closekey(); + Free; end; Screen.Cursor := crDefault; end; diff --git a/source/mysqlconn.pas b/source/mysqlconn.pas index 1efde33d..e38882bf 100644 --- a/source/mysqlconn.pas +++ b/source/mysqlconn.pas @@ -25,6 +25,7 @@ type constructor Create(AConn : POpenConnProf); destructor Destroy(); override; function Connect() : Integer; + procedure Disconnect(); property IsConnected : Boolean read GetIsConnected; property IsAlive : Boolean read GetIsAlive; property Connection : TZConnection read FConn; @@ -49,6 +50,7 @@ function TMysqlConn.Connect(): Integer; begin FLastError := ''; + if FConn.Connected then FConn.Disconnect; with FOpenConn.MysqlParams do begin FConn.Protocol := 'mysql'; @@ -80,9 +82,15 @@ begin end; +procedure TMysqlConn.Disconnect; +begin + if FConn.Connected then FConn.Disconnect; +end; + destructor TMysqlConn.Destroy; begin + if FConn.Connected then FConn.Disconnect; FreeAndNil (FConn); inherited; end; diff --git a/source/mysqlquerythread.pas b/source/mysqlquerythread.pas index 81d5049a..baf9ea25 100644 --- a/source/mysqlquerythread.pas +++ b/source/mysqlquerythread.pas @@ -56,11 +56,11 @@ type Comment : String; end; - TMysqlConnectThread = class(TThread) + {*TMysqlConnectThread = class(TThread) private protected public - end; + end;*} TMysqlQueryThread = class(TThread) private diff --git a/source/optimizetables.pas b/source/optimizetables.pas index 1bc5dbe3..bce8c20c 100644 --- a/source/optimizetables.pas +++ b/source/optimizetables.pas @@ -129,6 +129,8 @@ begin sql := StringReplace(pseudoSql, '$table', mainform.mask(TablesCheckListBox.Items[i]), [rfReplaceAll]); ds := Mainform.ChildWin.GetResults(sql); AddResults(ds); + ds.Close; + FreeAndNil(ds); TablesCheckListBox.Checked[i] := false; end; end; diff --git a/source/sqlhelp.pas b/source/sqlhelp.pas index 5c8a02b3..edf12b08 100644 --- a/source/sqlhelp.pas +++ b/source/sqlhelp.pas @@ -132,6 +132,7 @@ begin ParentNode.DeleteChildren; topic := ParentNode.Text; end; + ds := nil; try Screen.Cursor := crHourglass; ds := m.GetResults( 'HELP "'+topic+'"' ); @@ -154,6 +155,7 @@ begin ds.Next; end; finally + if ds <> nil then ds.Close; FreeAndNil( ds ); Screen.Cursor := crDefault; end; @@ -261,6 +263,7 @@ begin Caption := DEFAULT_WINDOW_CAPTION; result := false; // Keyword not found yet + ds := nil; if Keyword <> '' then try Screen.Cursor := crHourglass; @@ -278,6 +281,7 @@ begin result := true; end; finally + if ds <> nil then ds.Close; FreeAndNil( ds ); Screen.Cursor := crDefault; end; diff --git a/source/tbl_properties.dfm b/source/tbl_properties.dfm index fd95e2c4..f06e2eb5 100644 --- a/source/tbl_properties.dfm +++ b/source/tbl_properties.dfm @@ -17,6 +17,7 @@ object tbl_properties_form: Ttbl_properties_form Position = poMainFormCenter OnClose = FormClose OnCreate = FormCreate + OnDestroy = FormDestroy OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 diff --git a/source/tbl_properties.pas b/source/tbl_properties.pas index 83f3f33f..4c7553d1 100644 --- a/source/tbl_properties.pas +++ b/source/tbl_properties.pas @@ -35,6 +35,7 @@ type popupSynMemo: TPopupMenu; menuCopy: TMenuItem; menuSelectAll: TMenuItem; + procedure FormDestroy(Sender: TObject); procedure comboCharsetChange(Sender: TObject); procedure editNameChange(Sender: TObject); @@ -71,8 +72,8 @@ var charset : String; begin try - dsEngines := Mainform.Childwin.ExecSelectQuery('SHOW ENGINES'); - dsCollations := Mainform.Childwin.ExecSelectQuery('SHOW COLLATION'); + dsEngines := Mainform.Childwin.GetResults('SHOW ENGINES'); + dsCollations := Mainform.Childwin.GetResults('SHOW COLLATION'); except // Ignore it when the above statements don't work on pre 4.1 servers. // If the list(s) are nil, disable the combobox(es), so we create the db without charset. @@ -125,6 +126,14 @@ begin end; +procedure Ttbl_properties_form.FormDestroy(Sender: TObject); +begin + if dsEngines <> nil then dsEngines.Close; + FreeAndNil(dsEngines); + if dsCollations <> nil then dsCollations.Close; + FreeAndNil(dsCollations); +end; + {** Form gets displayed. } @@ -185,6 +194,8 @@ begin editAutoincrement.Enabled := True; end; lblAutoincrement.Enabled := editAutoincrement.Enabled; + ds.Close; + FreeAndNil(ds); // SQL preview sql := 'SHOW CREATE TABLE '; diff --git a/source/threading.pas b/source/threading.pas index 3c306554..3f340881 100644 --- a/source/threading.pas +++ b/source/threading.pas @@ -221,5 +221,8 @@ end; initialization working := TThreadList.Create; +finalization + FreeAndNil(working); + end. diff --git a/source/usermanager.pas b/source/usermanager.pas index 82a23863..9bbb9c5a 100644 --- a/source/usermanager.pas +++ b/source/usermanager.pas @@ -88,6 +88,7 @@ type procedure GetResColumns; function getColumnNamesOrValues( which: String = 'columns' ): TStringList; function getPrivColumns( privtable: String ): TDataSet; + procedure clearCache; private @@ -250,7 +251,9 @@ begin WriteBool('Compressed', false); WriteString('OnlyDBs', ''); CloseKey; + Free; end; + Free; end; priv := ''; @@ -355,6 +358,7 @@ begin tnu.SelectedIndex := ICONINDEX_FIELD; ZQueryColumnNames.Next; end; + ZQueryColumnNames.Close; FreeAndNil( ZQueryColumnNames ); end; @@ -824,11 +828,7 @@ end; procedure TUserManagerForm.FormClose(Sender: TObject; var Action: TCloseAction); begin - // free memory - FreeAndNil( ZQueryUsers ); - FreeAndNil( ZQueryDBs ); - FreeAndNil( ZQueryTables ); - FreeAndNil( ZQueryColumns ); + clearCache; end; @@ -923,13 +923,30 @@ begin EditUserWindow(self); end; -procedure TUserManagerForm.Button1Click(Sender: TObject); +procedure TUserManagerForm.clearCache; begin // free memory + if ZQueryUsers <> nil then ZQueryUsers.Close; FreeAndNil( ZQueryUsers ); + if ZQueryDBs <> nil then ZQueryDBs.Close; FreeAndNil( ZQueryDBs ); + if ZQueryTables <> nil then ZQueryTables.Close; FreeAndNil( ZQueryTables ); + if ZQueryColumns <> nil then ZQueryColumns.Close; FreeAndNil( ZQueryColumns ); + if ColumnsUsers <> nil then ColumnsUsers.Close; + FreeAndNil(ColumnsUsers); + if ColumnsDB <> nil then ColumnsDB.Close; + FreeAndNil(ColumnsDB); + if ColumnsTables <> nil then ColumnsTables.Close; + FreeAndNil(ColumnsTables); + if ColumnsColumns <> nil then ColumnsColumns.Close; + FreeAndNil(ColumnsColumns); +end; + +procedure TUserManagerForm.Button1Click(Sender: TObject); +begin + clearCache; ShowPrivilegesControls(false, true, false); TreeViewUsers.Items.Clear; PageControl1.OnChange(self);