Skip to content

Commit 62fd4df

Browse files
author
mergerepo
committed
Merge remote branch 'origin/master' into edge
(no-precommit-check no-tn-check)
2 parents d013139 + d539f1a commit 62fd4df

File tree

4 files changed

+82
-20
lines changed

4 files changed

+82
-20
lines changed

source/ada/lsp-ada_driver.adb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ procedure LSP.Ada_Driver is
175175
(VSS.Standard_Paths.Home_Location)
176176
else ALS_Home)));
177177
ALS_Dir : constant Virtual_File := Home_Dir / ".als";
178+
Clean_ALS_Dir : Boolean := False;
178179
GNATdebug : constant Virtual_File := Create_From_Base
179180
(".gnatdebug");
180181

@@ -248,6 +249,8 @@ begin
248249
Parse_Config_File (GNATdebug);
249250

250251
elsif ALS_Dir.Is_Directory then
252+
Clean_ALS_Dir := True;
253+
251254
-- Search for custom traces config in traces.cfg
252255
Parse_Config_File (+Virtual_File'(ALS_Dir / "traces.cfg").Full_Name);
253256

@@ -345,7 +348,11 @@ begin
345348
end;
346349
end if;
347350

351+
Ada_Handler.Stop_File_Monitoring;
348352
Server.Finalize;
353+
if Clean_ALS_Dir then
354+
Ada_Handler.Clean_Logs (ALS_Dir);
355+
end if;
349356
Ada_Handler.Cleanup;
350357

351358
-- Clean secondary stack up

source/ada/lsp-ada_handlers.adb

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,17 +522,24 @@ package body LSP.Ada_Handlers is
522522
Self.Total_Files_Indexed := 0;
523523
end Release_Contexts_And_Project_Info;
524524

525+
--------------------------
526+
-- Stop_File_Monitoring --
527+
--------------------------
528+
529+
procedure Stop_File_Monitoring (Self : access Message_Handler) is
530+
begin
531+
if Self.File_Monitor.Assigned then
532+
Self.File_Monitor.Stop_Monitoring_Directories;
533+
end if;
534+
end Stop_File_Monitoring;
535+
525536
-------------
526537
-- Cleanup --
527538
-------------
528539

529540
procedure Cleanup (Self : access Message_Handler)
530541
is
531542
begin
532-
if Self.File_Monitor.Assigned then
533-
Self.File_Monitor.Stop_Monitoring_Directories;
534-
end if;
535-
536543
-- Cleanup documents
537544
for Document of Self.Open_Documents loop
538545
Free (Document);
@@ -546,6 +553,30 @@ package body LSP.Ada_Handlers is
546553
LSP.File_Monitors.Unchecked_Free (Self.File_Monitor);
547554
end Cleanup;
548555

556+
----------------
557+
-- Clean_Logs --
558+
----------------
559+
560+
procedure Clean_Logs (Self : access Message_Handler; Dir : Virtual_File) is
561+
Files : File_Array_Access := Read_Dir (Dir, Files_Only);
562+
Dummy : Boolean;
563+
Cpt : Integer := 0;
564+
begin
565+
Sort (Files.all);
566+
-- Browse the log files in reverse timestamp order
567+
for F of reverse Files.all loop
568+
-- Filter out files like traces.cfg
569+
if GNATCOLL.Utils.Ends_With (+F.Base_Name, ".log") then
570+
Cpt := Cpt + 1;
571+
-- Delete the old logs
572+
if Cpt > Self.Log_Threshold then
573+
Delete (F, Dummy);
574+
end if;
575+
end if;
576+
end loop;
577+
Unchecked_Free (Files);
578+
end Clean_Logs;
579+
549580
-----------------------
550581
-- Exit_Notification --
551582
-----------------------
@@ -4165,6 +4196,8 @@ package body LSP.Ada_Handlers is
41654196
"documentationStyle";
41664197
useCompletionSnippets : constant String :=
41674198
"useCompletionSnippets";
4199+
logThreshold : constant String :=
4200+
"logThreshold";
41684201

41694202
Ada : constant LSP.Types.LSP_Any := Value.settings.Get ("ada");
41704203
File : VSS.Strings.Virtual_String;
@@ -4243,6 +4276,10 @@ package body LSP.Ada_Handlers is
42434276
Self.Named_Notation_Threshold := Ada.Get (namedNotationThreshold);
42444277
end if;
42454278

4279+
if Ada.Has_Field (logThreshold) then
4280+
Self.Log_Threshold := Ada.Get (logThreshold);
4281+
end if;
4282+
42464283
-- Check the 'useCompletionSnippets' flag to see if we should use
42474284
-- snippets in completion (if the client supports it).
42484285
if not Self.Completion_Snippets_Enabled then

source/ada/lsp-ada_handlers.ads

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,14 @@ package LSP.Ada_Handlers is
6161
-- This procedure will be called when an unexpected error is raised in the
6262
-- request processing loop.
6363

64+
procedure Stop_File_Monitoring (Self : access Message_Handler);
65+
6466
procedure Cleanup (Self : access Message_Handler);
6567
-- Free memory referenced by Self
6668

69+
procedure Clean_Logs (Self : access Message_Handler; Dir : Virtual_File);
70+
-- Remove the oldest logs in Dir
71+
6772
subtype Context_Access is LSP.Ada_Context_Sets.Context_Access;
6873

6974
function From_File
@@ -332,6 +337,10 @@ private
332337
File_Monitor : LSP.File_Monitors.File_Monitor_Access;
333338
-- Filesystem monitoring
334339

340+
Log_Threshold : Natural := 10;
341+
-- Maximum number of logs (should be > to the number of servers run
342+
-- simultaneously)
343+
335344
---------------------------------------
336345
-- Experimental Client Capabilities --
337346
---------------------------------------

testsuite/leaks.supp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@
2222
fun:gpr__err__error_msg
2323
}
2424

25+
### T114-020 leaks with extending project and custom renaming
26+
{
27+
GPR leak
28+
Memcheck:Leak
29+
match-leak-kinds: definite
30+
fun:malloc
31+
fun:gnatcoll__memory__alloc
32+
fun:system__pool_global__allocate
33+
fun:gpr__nmsc__add_source
34+
fun:gpr__nmsc__check_file
35+
fun:gpr__nmsc__search_directories
36+
fun:gpr__nmsc__find_sources
37+
fun:gpr__nmsc__look_for_sources
38+
fun:gpr__nmsc__process_naming_scheme__check
39+
fun:gpr__nmsc__process_naming_scheme__recursive_check.71.isra.0
40+
fun:gpr__nmsc__process_naming_scheme__check_all_projects__recursive_check_context__recursive_check.68
41+
fun:gpr__nmsc__process_naming_scheme__check_all_projects__recursive_check_context__recursive_check.68
42+
fun:gpr__nmsc__process_naming_scheme__check_all_projects__recursive_check_context__recursive_check.68
43+
fun:gpr__nmsc__process_naming_scheme__check_all_projects__recursive_check_context.67.constprop.0
44+
fun:gpr__nmsc__process_naming_scheme__check_all_projects
45+
fun:gpr__nmsc__process_naming_scheme
46+
fun:gpr__proc__check
47+
fun:gpr__proc__process_project_tree_phase_2
48+
}
49+
2550
### SC20-039 leaks when loading library aggregate projects
2651
{
2752
<insert_a_suppression_name_here>
@@ -44,22 +69,6 @@
4469
fun:gpr__proc__recursive_process__process_aggregated_projects
4570
}
4671

47-
### T114-020 leaks with extending project and custom renaming
48-
{
49-
<insert_a_suppression_name_here>
50-
Memcheck:Leak
51-
match-leak-kinds: definite
52-
fun:malloc
53-
fun:__gnat_malloc
54-
fun:system__pool_global__allocate
55-
fun:gpr__nmsc__add_source
56-
fun:gpr__nmsc__check_file
57-
fun:gpr__nmsc__search_directories__2
58-
fun:gpr__nmsc__find_sources
59-
fun:gpr__nmsc__look_for_sources
60-
fun:gpr__nmsc__process_naming_scheme__check
61-
}
62-
6372
# Valgrind limitation: GNAT’s superaligned secondary stack chunk
6473
# appears to be leaked, but we actually have a pointer to the
6574
# middle of the allocated memory block.

0 commit comments

Comments
 (0)