Skip to content

Commit

Permalink
Merge branch 'mr/jicquel/gnatcoll-core#75.fix-memory-leaks' into 'mas…
Browse files Browse the repository at this point in the history
…ter'

Fix memory leaks in GNATCOLL

See merge request eng/toolchain/gnatcoll-core!137
  • Loading branch information
Jicquel committed Oct 9, 2024
2 parents 102bdd5 + 54b7e08 commit db878d8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions testsuite/tests/hash/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
description: Basic GNATCOLL.Hash test
timeout: 500 # Default time is not enough for the valgrind run
control:
- [SKIP, "env.target.machine == 'qemu'",
"Not enough disk space on cross qemu configuration"]
13 changes: 9 additions & 4 deletions testsuite/tests/paragraph_filling/text/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function Test return Integer is

subtype Acc is GNAT.Strings.String_Access;

S_In : constant Acc := Read_File (Create_From_Base ("in.txt"));
S_Gr : constant Acc := Read_File (Create_From_Base ("greedy.txt"));
S_Pr : constant Acc := Read_File (Create_From_Base ("pretty.txt"));
S_Kn : constant Acc := Read_File (Create_From_Base ("knuth.txt"));
S_In : Acc := Read_File (Create_From_Base ("in.txt"));
S_Gr : Acc := Read_File (Create_From_Base ("greedy.txt"));
S_Pr : Acc := Read_File (Create_From_Base ("pretty.txt"));
S_Kn : Acc := Read_File (Create_From_Base ("knuth.txt"));

begin

Expand All @@ -58,5 +58,10 @@ begin
A.Assert (S_Kn.all, ASU.To_String (Knuth_Fill (S_In.all, 60)),
"Knuth fill");

GNAT.Strings.Free (S_In);
GNAT.Strings.Free (S_Gr);
GNAT.Strings.Free (S_Pr);
GNAT.Strings.Free (S_Kn);

return A.Report;
end Test;
6 changes: 4 additions & 2 deletions testsuite/tests/promises/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
with Ada.Text_IO; use Ada.Text_IO;
with GNATCOLL.Promises; use GNATCOLL.Promises;
with Test_Promises_Support; use Test_Promises_Support;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

with Test_Assert;

Expand Down Expand Up @@ -64,7 +65,7 @@ begin
and new Convert_Float
and new Display_String);
Put_Line ("Failing...");
Message := new String'("Explicit failure");
Message := To_Unbounded_String ("Explicit failure");
P.Set_Error ("Explicit failure");
A.Assert (A.Assert_Count, 7, "expected number of asserts #2");

Expand All @@ -74,7 +75,8 @@ begin
and new Fail_On_Float
and (new Display_String & new Display_String));
Baseline := 3;
Message := new String'("explicit");

Message := To_Unbounded_String ("explicit");
P.Set_Value (3);
A.Assert (A.Assert_Count, 11, "expected number of asserts #3");

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/promises/test_promises_support.adb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ package body Test_Promises_Support is
pragma Unreferenced (Self);
begin
Put_Line ("Display_String.Failed because " & Reason);
A.Assert (Reason, Message.all, "expected reason");
A.Assert (Reason, To_String (Message), "expected reason");
end On_Error;

overriding procedure On_Next
Expand Down
3 changes: 2 additions & 1 deletion testsuite/tests/promises/test_promises_support.ads
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
------------------------------------------------------------------------------

with GNATCOLL.Promises; use GNATCOLL.Promises;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

package Test_Promises_Support is

Baseline : Integer := 0;
Message : access String;
Message : Unbounded_String;
-- Values that Assert routines should verify

package Int_Promises is new Promises (Integer);
Expand Down
12 changes: 11 additions & 1 deletion testsuite/tests/vfs/basic/test.adb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ function Test return Integer is
Write (W, "first word ");
Close (W);
W := Write_File (F, Append => True);
Write (W, Interfaces.C.Strings.New_String ("second word"));

declare
use Interfaces.C.Strings;

C_String : chars_ptr :=
Interfaces.C.Strings.New_String ("second word");
begin
Write (W, C_String);
Free (C_String);
end;

Close (W);

-- Check whether the file exists
Expand Down

0 comments on commit db878d8

Please sign in to comment.