         if closeOnDeinit && stream.streamStatus != .closed {
             stream.close()
         }
+        free(buffer)
+        free(tempBuffer)
     }
 
     internal var hasBytesAvailable: Bool {


    internal func readUInt32() throws -> UInt32 {
        let bufferSize = 4
        let length = try readStream(&buffer, maxLength: bufferSize)
        if length < 0 {
            throw CSVError.streamErrorHasOccurred(error: stream.streamError!)
        }
        if length != bufferSize {
            throw CSVError.stringEncodingMismatch
        }
        return try UnsafePointer(buffer).withMemoryRebound(to: UInt32.self, capacity: 1) {
            switch endian {
            case .big:
                return CFSwapInt32BigToHost($0[0])


    internal func readUInt16() throws -> UInt16 {
        let bufferSize = 2
        let length = try readStream(buffer, maxLength: bufferSize)
        if length < 0 {
            throw CSVError.streamErrorHasOccurred(error: stream.streamError!)
        }
        if length != bufferSize {
            throw CSVError.stringEncodingMismatch
        }
        return try buffer.withMemoryRebound(to: UInt16.self, capacity: 1) {
            switch endian {
            case .big:
                return CFSwapInt16BigToHost($0[0])
