@@ -174,9 +174,6 @@ package body LSP.Ada_Handlers is
174174 procedure Index_Files (Self : access Message_Handler);
175175 -- Index all loaded files in each context. Emit progresormation.
176176
177- procedure Unchecked_Free is new Ada.Unchecked_Deallocation
178- (LSP.Ada_Documents.Document, Internal_Document_Access);
179-
180177 procedure Release_Contexts_And_Project_Info (Self : access Message_Handler);
181178 -- Release the memory associated to project information in Self
182179
@@ -528,20 +525,24 @@ package body LSP.Ada_Handlers is
528525 -- Cleanup --
529526 -- -----------
530527
531- procedure Cleanup (Self : access Message_Handler) is
528+ procedure Cleanup (Self : access Message_Handler)
529+ is
532530 begin
533531 if Self.File_Monitor.Assigned then
534532 Self.File_Monitor.Stop_Monitoring_Directories;
535533 end if ;
536534
537535 -- Cleanup documents
538536 for Document of Self.Open_Documents loop
539- Unchecked_Free (Document);
537+ Free (Document);
540538 end loop ;
541539 Self.Open_Documents.Clear;
542540
543541 -- Cleanup contexts, project and environment
544542 Self.Release_Contexts_And_Project_Info;
543+
544+ -- Free the file monitor
545+ LSP.File_Monitors.Unchecked_Free (Self.File_Monitor);
545546 end Cleanup ;
546547
547548 -- ---------------------
@@ -2615,7 +2616,7 @@ package body LSP.Ada_Handlers is
26152616 Context.Flush_Document (File);
26162617 end loop ;
26172618
2618- Unchecked_Free (Document);
2619+ Free (Document);
26192620
26202621 else
26212622 -- We have received a didCloseTextDocument but the document was
@@ -3748,7 +3749,7 @@ package body LSP.Ada_Handlers is
37483749 (Document.all , Context.all , Pattern,
37493750 Canceled.Has_Been_Canceled'Access , Result.result);
37503751
3751- Unchecked_Free (Internal_Document_Access (Document));
3752+ Free (Internal_Document_Access (Document));
37523753 end ;
37533754 else
37543755 Self.Get_Symbols
@@ -5969,6 +5970,18 @@ package body LSP.Ada_Handlers is
59695970 end if ;
59705971 end Publish_Diagnostics ;
59715972
5973+ -- --------
5974+ -- Free --
5975+ -- --------
5976+
5977+ procedure Free (Self : in out Internal_Document_Access) is
5978+ procedure Unchecked_Free is new Ada.Unchecked_Deallocation
5979+ (LSP.Ada_Documents.Document, Internal_Document_Access);
5980+ begin
5981+ Self.Cleanup;
5982+ Unchecked_Free (Self);
5983+ end Free ;
5984+
59725985 -- ----------------
59735986 -- Show_Message --
59745987 -- ----------------
0 commit comments