summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-12-28 23:01:11 +0100
committerAraq <rumpf_a@web.de>2014-12-28 23:01:11 +0100
commitcfb76164b875e4a8e3f5cb1fb8c298d5e3416cab (patch)
tree4b23e7304d7755dbc130d9b8075d8c77613a7d5c /lib
parenta0ad3aa1836902c5c478e57c8fbee75c60a0a155 (diff)
downloadNim-cfb76164b875e4a8e3f5cb1fb8c298d5e3416cab.tar.gz
fixes a long standing openssl wrapper bug: pass C compliant allocation functions to CRYPTO_set_mem_functions
Diffstat (limited to 'lib')
-rw-r--r--lib/wrappers/openssl.nim11
1 files changed, 10 insertions, 1 deletions
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.}