Commit 6718e9e 1 parent e7d0fb6 commit 6718e9e Copy full SHA for 6718e9e
File tree 3 files changed +31
-1
lines changed
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ local ffi_str = ffi.string
6
6
local floor = math.floor
7
7
8
8
require " resty.openssl.include.bn"
9
+ local crypto_macro = require (" resty.openssl.include.crypto" )
9
10
local format_error = require (" resty.openssl.err" ).format_error
10
11
11
12
local _M = {}
@@ -50,7 +51,9 @@ function _M:to_hex()
50
51
if buf == nil then
51
52
return nil , format_error (" bn:to_hex" )
52
53
end
53
- return ffi_str (buf ), nil
54
+ local s = ffi_str (buf )
55
+ crypto_macro .OPENSSL_free (buf )
56
+ return s , nil
54
57
end
55
58
56
59
function _M .from_binary (s )
Original file line number Diff line number Diff line change
1
+ local ffi = require " ffi"
2
+ local C = ffi .C
3
+
4
+ local OPENSSL_10 = require (" resty.openssl.version" ).OPENSSL_10
5
+ local OPENSSL_11 = require (" resty.openssl.version" ).OPENSSL_11
6
+
7
+ local OPENSSL_free
8
+ if OPENSSL_10 then
9
+ ffi .cdef [[
10
+ void CRYPTO_free (void * ptr );
11
+ ]]
12
+ OPENSSL_free = C .CRYPTO_free
13
+ elseif OPENSSL_11 then
14
+ ffi .cdef [[
15
+ void CRYPTO_free (void * ptr , const char * file , int line );
16
+ ]]
17
+ OPENSSL_free = function (ptr )
18
+ -- file and line is for debuggin only, since we can't know the c file info
19
+ -- the macro is expanded, just ignore this
20
+ C .CRYPTO_free (ptr , " " , 0 )
21
+ end
22
+ end
23
+
24
+ return {
25
+ OPENSSL_free = OPENSSL_free ,
26
+ }
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ bn:to_binary failed
105
105
ngx. log (ngx. ERR, err)
106
106
return
107
107
end
108
+ -- valgrind might warn about double free on this test because of the following
108
109
require (' ffi' ). C. BN_free(bn. ctx)
109
110
local b, err = bn2: to_binary()
110
111
if err then
You can’t perform that action at this time.
0 commit comments