фикс утечек

This commit is contained in:
PC1\PTyTb 2025-08-08 19:11:31 +03:00
parent 71cdcc9909
commit 04b5259737
1 changed files with 76 additions and 85 deletions

View File

@ -192,14 +192,13 @@ end;
procedure TTTW_Bot.ReadDB; procedure TTTW_Bot.ReadDB;
function XorDecryptToStrings(const InputFile, Key: string): TStrings; function XorDecryptToStrings(const InputFile, Key: string): TStrings;
var var
InStream: TFileStream; InStream: TFileStream;
MemStream: TMemoryStream; MemStream: TMemoryStream;
KeyBytes: TBytes; KeyBytes: TBytes;
KeyLen, KeyIndex: integer; KeyLen, KeyIndex: integer;
B: Byte; B: Byte;
begin begin
// Преобразуем ключ в байты с использованием ANSI кодировки
KeyBytes := TEncoding.ANSI.GetBytes(Key); KeyBytes := TEncoding.ANSI.GetBytes(Key);
KeyLen := Length(KeyBytes); KeyLen := Length(KeyBytes);
if KeyLen = 0 then if KeyLen = 0 then
@ -210,7 +209,6 @@ procedure TTTW_Bot.ReadDB;
MemStream := TMemoryStream.Create; MemStream := TMemoryStream.Create;
try try
KeyIndex := 0; KeyIndex := 0;
// Расшифровываем данные и записываем в поток в памяти
while InStream.Position < InStream.Size do while InStream.Position < InStream.Size do
begin begin
InStream.ReadBuffer(B, 1); InStream.ReadBuffer(B, 1);
@ -218,15 +216,12 @@ procedure TTTW_Bot.ReadDB;
MemStream.WriteBuffer(B, 1); MemStream.WriteBuffer(B, 1);
KeyIndex := (KeyIndex + 1) mod KeyLen; KeyIndex := (KeyIndex + 1) mod KeyLen;
end; end;
// Преобразуем данные из потока в TStrings MemStream.Position := 0;
MemStream.Position := 0; // Сбрасываем позицию для чтения
Result := TStringList.Create; Result := TStringList.Create;
try try
// Используем ANSI кодировку для преобразования байтов в строку
Result.LoadFromStream(MemStream, TEncoding.ANSI); Result.LoadFromStream(MemStream, TEncoding.ANSI);
except except
// В случае ошибки освобождаем ресурсы и пробрасываем исключение Result.Free; // Îñâîáîæäàåì ïðè îøèáêå çàãðóçêè
Result.Free;
raise; raise;
end; end;
finally finally
@ -235,8 +230,7 @@ procedure TTTW_Bot.ReadDB;
finally finally
InStream.Free; InStream.Free;
end; end;
end; end;
// Çàãðóçêà êîìïîíåíòîâ íàñòðîåê (TEdit, TCheckBox) // Çàãðóçêà êîìïîíåíòîâ íàñòðîåê (TEdit, TCheckBox)
procedure LoadSettingsComponents; procedure LoadSettingsComponents;
var var
@ -274,27 +268,25 @@ procedure TTTW_Bot.ReadDB;
end; end;
// Çàãðóçêà çàøèôðîâàííîãî êîíôèãà // Çàãðóçêà çàøèôðîâàííîãî êîíôèãà
procedure LoadEncryptedConfig; procedure LoadEncryptedConfig;
var var
sl: TStringList; tempList: TStrings; // Âðåìåííûé ñïèñîê äëÿ ðåçóëüòàòà
I: integer; I: integer;
begin begin
if not FileExists(myConst.cfg1) then if not FileExists(myConst.cfg1) then
Exit; Exit;
sl := TStringList.Create; tempList := nil; // Èíèöèàëèçàöèÿ
try try
sl.Assign(XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS')); tempList := XorDecryptToStrings(myConst.cfg1, 'fgvasrgEFAXFAFAS');
for I := 0 to sl.Count - 1 do
for I := 0 to tempList.Count - 1 do
begin begin
var var eqPos := Pos('=', tempList[I]);
eqPos := Pos('=', sl[I]);
if eqPos > 0 then if eqPos > 0 then
begin begin
var var Key := Trim(Copy(tempList[I], 1, eqPos - 1));
Key := Trim(Copy(sl[I], 1, eqPos - 1)); var Value := Trim(Copy(tempList[I], eqPos + 1, MaxInt));
var
Value := Trim(Copy(sl[I], eqPos + 1, MaxInt));
if Key = 'k1' then if Key = 'k1' then
appconst.TTV_ClientID := Value appconst.TTV_ClientID := Value
@ -322,10 +314,9 @@ procedure TTTW_Bot.ReadDB;
frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and frSettings1.btnGetDADef.Visible := (appconst.DA_ClientID <> '') and
(appconst.DA_Sicret <> '') and (appconst.DA_URL <> ''); (appconst.DA_Sicret <> '') and (appconst.DA_URL <> '');
finally finally
sl.Free; tempList.Free; // Âàæíî: îñâîáîæäàåì âðåìåííûé ñïèñîê!
end; end;
end; end;
// Çàãðóçêà íàñòðîåê óâåäîìëåíèé // Çàãðóçêà íàñòðîåê óâåäîìëåíèé
procedure LoadNotifySettings; procedure LoadNotifySettings;
var var