From cfb76164b875e4a8e3f5cb1fb8c298d5e3416cab Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 28 Dec 2014 23:01:11 +0100 Subject: fixes a long standing openssl wrapper bug: pass C compliant allocation functions to CRYPTO_set_mem_functions --- lib/wrappers/openssl.nim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/wrappers') diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim index ba25fbf1a..f091d8f46 100644 --- a/lib/wrappers/openssl.nim +++ b/lib/wrappers/openssl.nim @@ -280,9 +280,18 @@ when not useWinVersion: proc CRYPTO_set_mem_functions(a,b,c: pointer){.cdecl, dynlib: DLLUtilName, importc.} + proc allocWrapper(size: int): pointer {.cdecl.} = alloc(size) + proc reallocWrapper(p: pointer; newsize: int): pointer {.cdecl.} = + if p == nil: + if newSize > 0: result = alloc(newsize) + elif newsize == 0: dealloc(p) + else: result = realloc(p, newsize) + proc deallocWrapper(p: pointer) {.cdecl.} = + if p != nil: dealloc(p) + proc CRYPTO_malloc_init*() = when not useWinVersion: - CRYPTO_set_mem_functions(alloc, realloc, dealloc) + CRYPTO_set_mem_functions(allocWrapper, reallocWrapper, deallocWrapper) proc SSL_CTX_ctrl*(ctx: SslCtx, cmd: cInt, larg: int, parg: pointer): int{. cdecl, dynlib: DLLSSLName, importc.} -- cgit 1.4.1-2-gfad0