Skip to content

Commit 52b7282

Browse files
committed
Keep original OpenSSL memory allocation routines
no-tn-check Need to avoid crash process linked with libgmem. Crash is happening when OPENSSL_cleanup is freeing memory, but gmem.out file descriptor already closed. Add -t parameter for memory leak tests to be more strict.
1 parent 5609ae6 commit 52b7282

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

config/ssl/aws-net-ssl__openssl.adb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,8 @@ package body AWS.Net.SSL is
15751575
end if;
15761576
end Socket_Write;
15771577

1578+
Keep_M, Keep_R, Keep_F : System.Address;
1579+
15781580
-------------
15791581
-- Locking --
15801582
-------------
@@ -1709,6 +1711,12 @@ package body AWS.Net.SSL is
17091711
end if;
17101712
end loop;
17111713

1714+
if Keep_M /= System.Null_Address
1715+
and then TSSL.CRYPTO_set_mem_functions (Keep_M, Keep_R, Keep_F) = 0
1716+
then
1717+
Keep_M := System.Null_Address;
1718+
end if;
1719+
17121720
Finalized := True;
17131721
end Finalize;
17141722

@@ -2368,6 +2376,8 @@ package body AWS.Net.SSL is
23682376
end Version;
23692377

23702378
begin
2379+
TSSL.CRYPTO_get_mem_functions (M => Keep_M, R => Keep_R, F => Keep_F);
2380+
23712381
-- Set the RTL memory allocation routines is necessary only to be able
23722382
-- gnatmem control memory leak allocated inside of OpenSSL library.
23732383

@@ -2380,7 +2390,8 @@ begin
23802390
-- we are unable to setup our own memory allocation routines. GNATMEM
23812391
-- would not be aware of memory allocations inside of OpenSSL in this
23822392
-- case, but AWS is able to run anyway.
2383-
null;
2393+
2394+
Keep_M := System.Null_Address; -- To do not restore back
23842395
end if;
23852396

23862397
Locking.Initialize;

config/ssl/ssl-thin__openssl.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,9 @@ package SSL.Thin is
839839
-- Library initialization routines --
840840
-------------------------------------
841841

842+
procedure CRYPTO_get_mem_functions (M, R, F : out System.Address)
843+
with Import, Convention => C, External_Name => "CRYPTO_get_mem_functions";
844+
842845
function CRYPTO_set_mem_functions (M, R, F : System.Address) return int
843846
with Import, Convention => C, External_Name => "CRYPTO_set_mem_functions";
844847

regtests/0043_check_mem/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
# Run driver (2 loops)
77
run('check_mem', ['2'])
8-
exec_cmd('gnatmem', ['5', '-i', 'gmem.out', './check_mem'],
8+
exec_cmd('gnatmem', ['5', '-t', '-i', 'gmem.out', './check_mem'],
99
output_file='check_mem.run1')
1010

1111
# Run driver (10 loops)
1212
run('check_mem', ['10'])
13-
exec_cmd('gnatmem', ['5', '-i', 'gmem.out', './check_mem'],
13+
exec_cmd('gnatmem', ['5', '-t', '-i', 'gmem.out', './check_mem'],
1414
output_file='check_mem.run2')
1515

1616
# Now check that final water-mark for run1 and run2 is equal

regtests/0213_check_mem_nossl/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
# Run driver (2 loops)
2828
run('check_mem_nossl', ['2'])
29-
exec_cmd('gnatmem', ['5', '-i', 'gmem.out', './check_mem_nossl'],
29+
exec_cmd('gnatmem', ['5', '-t', '-i', 'gmem.out', './check_mem_nossl'],
3030
output_file='check_mem_nossl.run1')
3131

3232
# Run driver (10 loops)
3333
run('check_mem_nossl', ['10'])
34-
exec_cmd('gnatmem', ['5', '-i', 'gmem.out', './check_mem_nossl'],
34+
exec_cmd('gnatmem', ['5', '-t', '-i', 'gmem.out', './check_mem_nossl'],
3535
output_file='check_mem_nossl.run2')
3636

3737
# Now check that final water-mark for run1 and run2 is equal

0 commit comments

Comments
 (0)