Commit 3e37be71 by Philippe Gil Committed by Arnaud Charlet

prj.adb (Reset_Units_In_Table): New procedure.

2011-08-29  Philippe Gil  <gil@adacore.com>

	* prj.adb (Reset_Units_In_Table): New procedure.
	Reset units to avoid access to freed memory.

From-SVN: r178178
parent 94fb7608
2011-08-29 Philippe Gil <gil@adacore.com>
* prj.adb (Reset_Units_In_Table): New procedure.
Reset units to avoid access to freed memory.
2011-08-29 Thomas Quinot <quinot@adacore.com> 2011-08-29 Thomas Quinot <quinot@adacore.com>
* get_scos.adb: When reading a P statement SCO without a pragma name * get_scos.adb: When reading a P statement SCO without a pragma name
......
...@@ -71,6 +71,10 @@ package body Prj is ...@@ -71,6 +71,10 @@ package body Prj is
procedure Free_List (Languages : in out Language_List); procedure Free_List (Languages : in out Language_List);
-- Free memory allocated for the list of languages or sources -- Free memory allocated for the list of languages or sources
procedure Reset_Units_In_Table (Table : in out Units_Htable.Instance);
-- reset to No_Unit_Index Unit.File_Names (Spec).Unit &
-- Unit.File_Names (Impl).Unit for all Unis of the Table
procedure Free_Units (Table : in out Units_Htable.Instance); procedure Free_Units (Table : in out Units_Htable.Instance);
-- Free memory allocated for unit information in the project -- Free memory allocated for unit information in the project
...@@ -941,6 +945,29 @@ package body Prj is ...@@ -941,6 +945,29 @@ package body Prj is
end loop; end loop;
end Free_List; end Free_List;
--------------------------
-- Reset_Units_In_Table --
--------------------------
procedure Reset_Units_In_Table (Table : in out Units_Htable.Instance) is
Unit : Unit_Index;
begin
Unit := Units_Htable.Get_First (Table);
while Unit /= No_Unit_Index loop
if Unit.File_Names (Spec) /= null then
Unit.File_Names (Spec).Unit := No_Unit_Index;
end if;
if Unit.File_Names (Impl) /= null then
Unit.File_Names (Impl).Unit := No_Unit_Index;
end if;
Unit := Units_Htable.Get_Next (Table);
end loop;
end Reset_Units_In_Table;
---------------- ----------------
-- Free_Units -- -- Free_Units --
---------------- ----------------
...@@ -954,13 +981,10 @@ package body Prj is ...@@ -954,13 +981,10 @@ package body Prj is
begin begin
Unit := Units_Htable.Get_First (Table); Unit := Units_Htable.Get_First (Table);
while Unit /= No_Unit_Index loop while Unit /= No_Unit_Index loop
if Unit.File_Names (Spec) /= null then
Unit.File_Names (Spec).Unit := No_Unit_Index;
end if;
if Unit.File_Names (Impl) /= null then -- we cannot reset Unit.File_Names (Impl or Spec).Unit here as
Unit.File_Names (Impl).Unit := No_Unit_Index; -- Source_Data buffer is freed by the following instruction
end if; -- Free_List (Tree.Projects, Free_Project => True);
Unchecked_Free (Unit); Unchecked_Free (Unit);
Unit := Units_Htable.Get_Next (Table); Unit := Units_Htable.Get_Next (Table);
...@@ -1003,6 +1027,7 @@ package body Prj is ...@@ -1003,6 +1027,7 @@ package body Prj is
Source_Paths_Htable.Reset (Tree.Source_Paths_HT); Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
Source_Files_Htable.Reset (Tree.Source_Files_HT); Source_Files_Htable.Reset (Tree.Source_Files_HT);
Reset_Units_In_Table (Tree.Units_HT);
Free_List (Tree.Projects, Free_Project => True); Free_List (Tree.Projects, Free_Project => True);
Free_Units (Tree.Units_HT); Free_Units (Tree.Units_HT);
...@@ -1048,6 +1073,7 @@ package body Prj is ...@@ -1048,6 +1073,7 @@ package body Prj is
Tree.Replaced_Source_Number := 0; Tree.Replaced_Source_Number := 0;
Reset_Units_In_Table (Tree.Units_HT);
Free_List (Tree.Projects, Free_Project => True); Free_List (Tree.Projects, Free_Project => True);
Free_Units (Tree.Units_HT); Free_Units (Tree.Units_HT);
end Reset; end Reset;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment