Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -131,14 +131,14 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = [self allocMemoryWithSize: itemSize - count: count]; + _items = of_malloc(count, itemSize); _itemSize = itemSize; _count = count; + _freeWhenDone = true; memcpy(_items, items, count * itemSize); } @catch (id e) { [self release]; @throw e; @@ -244,10 +244,11 @@ stream = [URLHandler openItemAtURL: URL mode: @"r"]; _itemSize = 1; _count = 0; + _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { @@ -258,12 +259,11 @@ if (SIZE_MAX - _count < length) @throw [OFOutOfRangeException exception]; - _items = [self resizeMemory: _items - size: _count + length]; + _items = of_realloc(_items, _count + length, 1); memcpy(_items + _count, buffer, length); _count += length; } } @finally { free(buffer); @@ -290,13 +290,14 @@ if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; - _items = [self allocMemoryWithSize: count]; + _items = of_malloc(count, 1); _itemSize = 1; _count = count; + _freeWhenDone = true; cString = [string cStringWithEncoding: OF_STRING_ENCODING_ASCII]; for (size_t i = 0; i < count; i++) { Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -54,10 +54,11 @@ - (instancetype)init { self = [super init]; _itemSize = 1; + _freeWhenDone = true; return self; } - (instancetype)initWithItemSize: (size_t)itemSize @@ -67,10 +68,11 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _itemSize = itemSize; + _freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } @@ -90,15 +92,14 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = [self allocMemoryWithSize: itemSize - count: capacity]; - + _items = of_malloc(capacity, itemSize); _itemSize = itemSize; _capacity = capacity; + _freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } @@ -186,13 +187,11 @@ { if (SIZE_MAX - _count < 1) @throw [OFOutOfRangeException exception]; if (_count + 1 > _capacity) { - _items = [self resizeMemory: _items - size: _itemSize - count: _count + 1]; + _items = of_realloc(_items, _count + 1, _itemSize); _capacity = _count + 1; } memcpy(_items + _count * _itemSize, item, _itemSize); @@ -212,13 +211,11 @@ { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = [self resizeMemory: _items - size: _itemSize - count: _count + count]; + _items = of_realloc(_items, _count + count, _itemSize); _capacity = _count + count; } memcpy(_items + _count * _itemSize, items, count * _itemSize); _count += count; @@ -230,13 +227,11 @@ { if (count > SIZE_MAX - _count || idx > _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = [self resizeMemory: _items - size: _itemSize - count: _count + count]; + _items = of_realloc(_items, _count + count, _itemSize); _capacity = _count + count; } memmove(_items + (idx + count) * _itemSize, _items + idx * _itemSize, (_count - idx) * _itemSize); @@ -249,13 +244,11 @@ { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = [self resizeMemory: _items - size: _itemSize - count: _count + count]; + _items = of_realloc(_items, _count + count, _itemSize); _capacity = _count + count; } memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; @@ -276,13 +269,11 @@ _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize); _count -= range.length; @try { - _items = [self resizeMemory: _items - size: _itemSize - count: _count]; + _items = of_realloc(_items, _count, _itemSize);; _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -292,23 +283,20 @@ if (_count == 0) return; _count--; @try { - _items = [self resizeMemory: _items - size: _itemSize - count: _count]; + _items = of_realloc(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { - [self freeMemory: _items]; - + free(_items); _items = NULL; _count = 0; _capacity = 0; } Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -413,12 +413,12 @@ if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { - _items = [self allocMemoryWithSize: itemSize - count: count]; + _items = of_malloc(count, itemSize); + _freeWhenDone = true; memset(_items, 0, count * itemSize); #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) } else if (count * itemSize >= pageSize) _items = mapPages(OF_ROUND_UP_POW2(pageSize, count * itemSize) / pageSize);