Browse Source

Merge pull request #46 from yannickl/develop

[FIX] Memory leak with unsafe calloc
Marcin Krzyzanowski 10 years ago
parent
commit
324704ae78
1 changed files with 9 additions and 3 deletions
  1. 9 3
      CryptoSwift/HashBase.swift

+ 9 - 3
CryptoSwift/HashBase.swift

@@ -29,15 +29,21 @@ internal class HashBase {
         tmpMessage.appendBytes([0x80]) // append one bit (UInt8 with one bit) to message
         
         // append "0" bit until message length in bits ≡ 448 (mod 512)
-        var msgLength = tmpMessage.length;
-        var counter = 0;
+        var msgLength = tmpMessage.length
+        var counter = 0
+      
         while msgLength % len != (len - 8) {
             counter++
             msgLength++
         }
+      
         var bufZeros = UnsafeMutablePointer<UInt8>(calloc(counter, sizeof(UInt8)))
+      
         tmpMessage.appendBytes(bufZeros, length: counter)
-        
+      
+        bufZeros.destroy()
+        bufZeros.dealloc(1)
+      
         return tmpMessage
     }
 }