Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -246,23 +246,29 @@ _itemSize = 1; _count = 0; pageSize = [OFSystemInfo pageSize]; - buffer = [self allocMemoryWithSize: pageSize]; - - while (!stream.atEndOfStream) { - size_t length = [stream readIntoBuffer: buffer - length: pageSize]; - - if (SIZE_MAX - _count < length) - @throw [OFOutOfRangeException exception]; - - _items = [self resizeMemory: _items - size: _count + length]; - memcpy(_items + _count, buffer, length); - _count += length; + buffer = of_malloc(1, pageSize); + + @try { + while (!stream.atEndOfStream) { + size_t length = [stream + readIntoBuffer: buffer + length: pageSize]; + + if (SIZE_MAX - _count < length) + @throw [OFOutOfRangeException + exception]; + + _items = [self resizeMemory: _items + size: _count + length]; + memcpy(_items + _count, buffer, length); + _count += length; + } + } @finally { + of_free(buffer); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release];