Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -236,21 +236,21 @@ } - (id const *)objects { size_t count = self.count; - id *buffer = of_alloc(count, sizeof(id)); + id *buffer = OFAllocMemory(count, sizeof(id)); @try { [self getObjects: buffer inRange: OFRangeMake(0, count)]; return [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } } - (id)copy @@ -374,17 +374,17 @@ @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; - buffer = of_alloc(range.length, sizeof(*buffer)); + buffer = OFAllocMemory(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } @@ -823,31 +823,31 @@ #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block { OFArray *ret; size_t count = self.count; - id *tmp = of_alloc(count, sizeof(id)); + id *tmp = OFAllocMemory(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { - free(tmp); + OFFreeMemory(tmp); } return ret; } - (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block { OFArray *ret; size_t count = self.count; - id *tmp = of_alloc(count, sizeof(id)); + id *tmp = OFAllocMemory(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, @@ -856,11 +856,11 @@ tmp[i++] = object; }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { - free(tmp); + OFFreeMemory(tmp); } return ret; } Index: src/OFBitSetCharacterSet.m ================================================================== --- src/OFBitSetCharacterSet.m +++ src/OFBitSetCharacterSet.m @@ -46,11 +46,11 @@ exception]; newSize = OF_ROUND_UP_POW2(CHAR_BIT, c + 1) / CHAR_BIT; - _bitset = of_realloc(_bitset, newSize, 1); + _bitset = OFResizeMemory(_bitset, newSize, 1); memset(_bitset + _size, '\0', newSize - _size); _size = newSize; } @@ -66,11 +66,11 @@ return self; } - (void)dealloc { - free(_bitset); + OFFreeMemory(_bitset); [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character Index: src/OFBytesValue.m ================================================================== --- src/OFBytesValue.m +++ src/OFBytesValue.m @@ -27,11 +27,11 @@ self = [super init]; @try { _size = of_sizeof_type_encoding(objCType); _objCType = objCType; - _bytes = of_alloc(1, _size); + _bytes = OFAllocMemory(1, _size); memcpy(_bytes, bytes, _size); } @catch (id e) { [self release]; @throw e; @@ -40,11 +40,11 @@ return self; } - (void)dealloc { - free(_bytes); + OFFreeMemory(_bytes); [super dealloc]; } - (void)getValue: (void *)value size: (size_t)size Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -109,21 +109,21 @@ struct of_string_utf8_ivars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; - ivars = of_alloc_zeroed(1, sizeof(*ivars)); + ivars = OFAllocZeroedMemory(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (of_string_utf8_check(ivars->cString, ivars->cStringLength, &ivars->length)) { case 1: ivars->isUTF8 = true; break; case -1: - free(ivars); + OFFreeMemory(ivars); @throw [OFInvalidEncodingException exception]; } _cString = (char *)ivars; object_setClass(self, [OFConstantUTF8String class]); Index: src/OFDNSResolver.m ================================================================== --- src/OFDNSResolver.m +++ src/OFDNSResolver.m @@ -544,11 +544,11 @@ [_settings release]; [_delegate release]; [_queryData release]; [_TCPSocket release]; [_TCPQueryData release]; - free(_TCPBuffer); + OFFreeMemory(_TCPBuffer); [_cancelTimer release]; [super dealloc]; } @end @@ -1115,11 +1115,11 @@ context->_responseLength = 0; return nil; } if (context->_TCPBuffer == nil) - context->_TCPBuffer = of_alloc(MAX_DNS_RESPONSE_LENGTH, 1); + context->_TCPBuffer = OFAllocMemory(MAX_DNS_RESPONSE_LENGTH, 1); [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: 2]; return nil; } Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -123,11 +123,11 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = of_alloc(count, itemSize); + _items = OFAllocMemory(count, itemSize); _count = count; _itemSize = itemSize; _freeWhenDone = true; memcpy(_items, items, count * itemSize); @@ -187,19 +187,19 @@ # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif - buffer = of_alloc((size_t)size, 1); + buffer = OFAllocMemory((size_t)size, 1); file = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: (size_t)size]; } @finally { [file release]; } } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); [self release]; @throw e; } @@ -206,11 +206,11 @@ @try { self = [self initWithItemsNoCopy: buffer count: (size_t)size freeWhenDone: true]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } return self; } @@ -236,11 +236,11 @@ _count = 0; _itemSize = 1; _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer @@ -248,16 +248,17 @@ if (SIZE_MAX - _count < length) @throw [OFOutOfRangeException exception]; - _items = of_realloc(_items, _count + length, 1); + _items = OFResizeMemory(_items, + _count + length, 1); memcpy(_items + _count, buffer, length); _count += length; } } @finally { - free(buffer); + OFFreeMemory(buffer); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @@ -279,11 +280,11 @@ if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; - _items = of_alloc(count, 1); + _items = OFAllocMemory(count, 1); _count = count; _itemSize = 1; _freeWhenDone = true; cString = [string cStringWithEncoding: OFStringEncodingASCII]; @@ -372,11 +373,11 @@ } - (void)dealloc { if (_freeWhenDone) - free(_items); + OFFreeMemory(_items); [_parentData release]; [super dealloc]; } Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -775,11 +775,11 @@ } # endif #endif pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; @@ -790,11 +790,11 @@ @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } @@ -835,11 +835,11 @@ } # endif #endif pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; @@ -850,11 +850,11 @@ @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -96,11 +96,11 @@ handle->next->previous = handle->previous; if (firstHandle == handle) firstHandle = handle->next; - free(handle); + OFFreeMemory(handle); } OF_DESTRUCTOR() { for (OFFileHandle iter = firstHandle; iter != NULL; @@ -236,11 +236,11 @@ @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; #else - handle = of_alloc(1, sizeof(*handle)); + handle = OFAllocMemory(1, sizeof(*handle)); @try { if ((flags = parseMode(mode.UTF8String, &handle->append)) == -1) @throw [OFInvalidArgumentException exception]; @@ -298,11 +298,11 @@ if (firstHandle != NULL) firstHandle->previous = handle; firstHandle = handle; } @catch (id e) { - free(handle); + OFFreeMemory(handle); @throw e; } #endif objc_autoreleasePoolPop(pool); Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -644,11 +644,11 @@ size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { sourceStream = [[OFURLHandler handlerForURL: source] openItemAtURL: source mode: @"r"]; destinationStream = [[OFURLHandler handlerForURL: @@ -696,11 +696,11 @@ @throw e; } @finally { [sourceStream close]; [destinationStream close]; - free(buffer); + OFFreeMemory(buffer); } } else if ([type isEqual: OFFileTypeSymbolicLink]) { @try { OFString *linkDestination = attributes.fileSymbolicLinkDestination; Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -473,12 +473,11 @@ _status = (short)status; return true; } -- (bool)handleServerHeader: (OFString *)line - socket: (OFTCPSocket *)sock +- (bool)handleServerHeader: (OFString *)line socket: (OFTCPSocket *)sock { OFString *key, *value, *old; const char *lineC, *tmp; char *keyC; @@ -507,20 +506,20 @@ lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; - keyC = of_alloc(tmp - lineC + 1, 1); + keyC = OFAllocMemory(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { key = [OFString stringWithUTF8StringNoCopy: keyC freeWhenDone: true]; } @catch (id e) { - free(keyC); + OFFreeMemory(keyC); @throw e; } do { tmp++; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -147,11 +147,11 @@ @try { return [OFString stringWithUTF8StringNoCopy: cString freeWhenDone: true]; } @catch (id e) { - free(cString); + OFFreeMemory(cString); @throw e; } } @implementation OFHTTPServerResponse Index: src/OFInflateStream.m ================================================================== --- src/OFInflateStream.m +++ src/OFInflateStream.m @@ -192,11 +192,11 @@ #ifdef OF_INFLATE64_STREAM_M _slidingWindowMask = 0xFFFF; #else _slidingWindowMask = 0x7FFF; #endif - _slidingWindow = of_alloc_zeroed(_slidingWindowMask + 1, 1); + _slidingWindow = OFAllocZeroedMemory(_slidingWindowMask + 1, 1); } @catch (id e) { [self release]; @throw e; } @@ -206,14 +206,14 @@ - (void)dealloc { if (_stream != nil) [self close]; - free(_slidingWindow); + OFFreeMemory(_slidingWindow); if (_state == HUFFMAN_TREE) { - free(_context.huffmanTree.lengths); + OFFreeMemory(_context.huffmanTree.lengths); if (_context.huffmanTree.codeLenTree != NULL) of_huffman_tree_release( _context.huffmanTree.codeLenTree); } @@ -376,11 +376,11 @@ CTX.codeLenCodesCount = bits; } if OF_LIKELY (CTX.lengths == NULL) - CTX.lengths = of_alloc_zeroed(19, 1); + CTX.lengths = OFAllocZeroedMemory(19, 1); for (uint16_t i = CTX.receivedCount; i < CTX.codeLenCodesCount + 4; i++) { if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; @@ -392,18 +392,18 @@ CTX.codeLenTree = of_huffman_tree_construct( CTX.lengths, 19); CTX.treeIter = CTX.codeLenTree; - free(CTX.lengths); + OFFreeMemory(CTX.lengths); CTX.lengths = NULL; CTX.receivedCount = 0; CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) - CTX.lengths = of_alloc( + CTX.lengths = OFAllocMemory( CTX.litLenCodesCount + CTX.distCodesCount + 258, 1); for (uint16_t i = CTX.receivedCount; i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) { uint8_t j, count; @@ -483,11 +483,11 @@ CTX.litLenCodesCount + 257); CTX.distTree = of_huffman_tree_construct( CTX.lengths + CTX.litLenCodesCount + 257, CTX.distCodesCount + 1); - free(CTX.lengths); + OFFreeMemory(CTX.lengths); /* * litLenTree and distTree are at the same location in * _context.huffman and _context.huffmanTree, thus no need to * set them. Index: src/OFLHADecompressingStream.m ================================================================== --- src/OFLHADecompressingStream.m +++ src/OFLHADecompressingStream.m @@ -106,11 +106,11 @@ _distanceBits = distanceBits; _dictionaryBits = dictionaryBits; _slidingWindowMask = (1u << dictionaryBits) - 1; - _slidingWindow = of_alloc(_slidingWindowMask + 1, 1); + _slidingWindow = OFAllocMemory(_slidingWindowMask + 1, 1); memset(_slidingWindow, ' ', _slidingWindowMask + 1); } @catch (id e) { [self release]; @throw e; } @@ -121,20 +121,20 @@ - (void)dealloc { if (_stream != nil) [self close]; - free(_slidingWindow); + OFFreeMemory(_slidingWindow); if (_codeLenTree != NULL) of_huffman_tree_release(_codeLenTree); if (_litLenTree != NULL) of_huffman_tree_release(_litLenTree); if (_distTree != NULL) of_huffman_tree_release(_distTree); - free(_codesLengths); + OFFreeMemory(_codesLengths); [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ @@ -173,11 +173,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_alloc_zeroed(bits, 1); + _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = true; _state = STATE_CODE_LEN_TREE; goto start; case STATE_CODE_LEN_TREE: @@ -224,11 +224,11 @@ _codesReceived++; } _codeLenTree = of_huffman_tree_construct(_codesLengths, _codesCount); - free(_codesLengths); + OFFreeMemory(_codesLengths); _codesLengths = NULL; _state = STATE_LITLEN_CODES_COUNT; goto start; case STATE_CODE_LEN_TREE_SINGLE: @@ -254,11 +254,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_alloc_zeroed(bits, 1); + _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = false; _treeIter = _codeLenTree; _state = STATE_LITLEN_TREE; goto start; @@ -314,11 +314,11 @@ _codesLengths[_codesReceived++] = value - 2; } _litLenTree = of_huffman_tree_construct(_codesLengths, _codesCount); - free(_codesLengths); + OFFreeMemory(_codesLengths); _codesLengths = NULL; of_huffman_tree_release(_codeLenTree); _codeLenTree = NULL; @@ -344,11 +344,11 @@ goto start; } _codesCount = bits; _codesReceived = 0; - _codesLengths = of_alloc_zeroed(bits, 1); + _codesLengths = OFAllocZeroedMemory(bits, 1); _treeIter = _codeLenTree; _state = STATE_DIST_TREE; goto start; case STATE_DIST_TREE: @@ -379,11 +379,11 @@ _codesReceived++; } _distTree = of_huffman_tree_construct(_codesLengths, _codesCount); - free(_codesLengths); + OFFreeMemory(_codesLengths); _codesLengths = NULL; _treeIter = _litLenTree; _state = STATE_BLOCK_LITLEN; goto start; Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -81,21 +81,21 @@ OFListItem *next; for (OFListItem *iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; - free(iter); + OFFreeMemory(iter); } [super dealloc]; } - (OFListItem *)appendObject: (id)object { OFListItem *listItem; - listItem = of_alloc(1, sizeof(OFListItem)); + listItem = OFAllocMemory(1, sizeof(OFListItem)); listItem->object = [object retain]; listItem->next = NULL; listItem->previous = _lastListItem; if (_lastListItem != NULL) @@ -112,11 +112,11 @@ return listItem; } - (OFListItem *)prependObject: (id)object { - OFListItem *listItem = of_alloc(1, sizeof(OFListItem)); + OFListItem *listItem = OFAllocMemory(1, sizeof(OFListItem)); listItem->object = [object retain]; listItem->next = _firstListItem; listItem->previous = NULL; @@ -134,11 +134,11 @@ } - (OFListItem *)insertObject: (id)object beforeListItem: (OFListItem *)listItem { - OFListItem *newListItem = of_alloc(1, sizeof(OFListItem)); + OFListItem *newListItem = OFAllocMemory(1, sizeof(OFListItem)); newListItem->object = [object retain]; newListItem->next = listItem; newListItem->previous = listItem->previous; @@ -157,11 +157,11 @@ } - (OFListItem *)insertObject: (id)object afterListItem: (OFListItem *)listItem { - OFListItem *newListItem = of_alloc(1, sizeof(OFListItem)); + OFListItem *newListItem = OFAllocMemory(1, sizeof(OFListItem)); newListItem->object = [object retain]; newListItem->next = listItem->next; newListItem->previous = listItem; @@ -193,11 +193,11 @@ _count--; _mutations++; [listItem->object release]; - free(listItem); + OFFreeMemory(listItem); } - (id)firstObject { return (_firstListItem != NULL ? _firstListItem->object : nil); @@ -272,11 +272,11 @@ _mutations++; for (OFListItem *iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; - free(iter); + OFFreeMemory(iter); } _firstListItem = _lastListItem = NULL; } @@ -289,11 +289,11 @@ previous = NULL; @try { for (OFListItem *iter = _firstListItem; iter != NULL; iter = iter->next) { - listItem = of_alloc(1, sizeof(OFListItem)); + listItem = OFAllocMemory(1, sizeof(OFListItem)); listItem->object = [iter->object retain]; listItem->next = NULL; listItem->previous = previous; if (copy->_firstListItem == NULL) Index: src/OFLocale.m ================================================================== --- src/OFLocale.m +++ src/OFLocale.m @@ -77,11 +77,11 @@ if (language != NULL) *language = [OFString stringWithCString: locale encoding: enc]; } @finally { - free(locale); + OFFreeMemory(locale); } } #endif static bool Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -150,11 +150,11 @@ _capacity *= 2; if (_capacity < MIN_CAPACITY) _capacity = MIN_CAPACITY; - _buckets = of_alloc_zeroed(_capacity, sizeof(*_buckets)); + _buckets = OFAllocZeroedMemory(_capacity, sizeof(*_buckets)); if (of_hash_seed != 0) _rotate = of_random16() & 31; } @catch (id e) { [self release]; @@ -169,15 +169,15 @@ for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deleted) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); - free(_buckets[i]); + OFFreeMemory(_buckets[i]); } } - free(_buckets); + OFFreeMemory(_buckets); [super dealloc]; } static void @@ -208,11 +208,11 @@ */ if ((capacity < self->_capacity && count > self->_count) || capacity < MIN_CAPACITY) return; - buckets = of_alloc_zeroed(capacity, sizeof(*buckets)); + buckets = OFAllocZeroedMemory(capacity, sizeof(*buckets)); for (unsigned long i = 0; i < self->_capacity; i++) { if (self->_buckets[i] != NULL && self->_buckets[i] != &deleted) { unsigned long j, last; @@ -235,11 +235,11 @@ buckets[j] = self->_buckets[i]; } } - free(self->_buckets); + OFFreeMemory(self->_buckets); self->_buckets = buckets; self->_capacity = capacity; } static void @@ -302,24 +302,24 @@ } if (i >= last) @throw [OFOutOfRangeException exception]; - bucket = of_alloc(1, sizeof(*bucket)); + bucket = OFAllocMemory(1, sizeof(*bucket)); @try { bucket->key = self->_keyFunctions.retain(key); } @catch (id e) { - free(bucket); + OFFreeMemory(bucket); @throw e; } @try { bucket->object = self->_objectFunctions.retain(object); } @catch (id e) { self->_keyFunctions.release(bucket->key); - free(bucket); + OFFreeMemory(bucket); @throw e; } bucket->hash = hash; @@ -463,11 +463,11 @@ _mutations++; _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); - free(_buckets[i]); + OFFreeMemory(_buckets[i]); _buckets[i] = &deleted; _count--; resizeForCount(self, _count); @@ -487,11 +487,11 @@ if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); - free(_buckets[i]); + OFFreeMemory(_buckets[i]); _buckets[i] = &deleted; _count--; _mutations++; resizeForCount(self, _count); @@ -511,18 +511,18 @@ } _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); - free(_buckets[i]); + OFFreeMemory(_buckets[i]); _buckets[i] = NULL; } } _count = 0; _capacity = MIN_CAPACITY; - _buckets = of_realloc(_buckets, _capacity, sizeof(*_buckets)); + _buckets = OFResizeMemory(_buckets, _capacity, sizeof(*_buckets)); /* * Get a new random value for _rotate, so that it is not less secure * than creating a new hash map. */ Index: src/OFMapTableDictionary.m ================================================================== --- src/OFMapTableDictionary.m +++ src/OFMapTableDictionary.m @@ -333,11 +333,11 @@ OFArray *ret; id *keys; size_t count; count = _mapTable.count; - keys = of_alloc(count, sizeof(*keys)); + keys = OFAllocMemory(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; @@ -353,11 +353,11 @@ objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: keys count: count]; } @finally { - free(keys); + OFFreeMemory(keys); } return ret; } @@ -366,11 +366,11 @@ OFArray *ret; id *objects; size_t count; count = _mapTable.count; - objects = of_alloc(count, sizeof(*objects)); + objects = OFAllocMemory(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; @@ -386,11 +386,11 @@ objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: objects count: count]; } @finally { - free(objects); + OFFreeMemory(objects); } return ret; } Index: src/OFMethodSignature.m ================================================================== --- src/OFMethodSignature.m +++ src/OFMethodSignature.m @@ -593,11 +593,11 @@ length = strlen(types); if (length == 0) @throw [OFInvalidFormatException exception]; - _types = of_alloc(length + 1, 1); + _types = OFAllocMemory(length + 1, 1); memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; _offsets = [[OFMutableData alloc] @@ -667,11 +667,11 @@ return self; } - (void)dealloc { - free(_types); + OFFreeMemory(_types); [_typesPointers release]; [_offsets release]; [super dealloc]; } Index: src/OFMutableAdjacentArray.m ================================================================== --- src/OFMutableAdjacentArray.m +++ src/OFMutableAdjacentArray.m @@ -231,21 +231,21 @@ if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; - copy = of_alloc(range.length, sizeof(*copy)); + copy = OFAllocMemory(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { - free(copy); + OFFreeMemory(copy); } } - (void)removeLastObject { Index: src/OFMutableData.m ================================================================== --- src/OFMutableData.m +++ src/OFMutableData.m @@ -88,11 +88,11 @@ @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; - _items = of_alloc(capacity, itemSize); + _items = OFAllocMemory(capacity, itemSize); _itemSize = itemSize; _capacity = capacity; _freeWhenDone = true; } @catch (id e) { [self release]; @@ -119,11 +119,11 @@ freeWhenDone: (bool)freeWhenDone { self = [self initWithItems: items count: count itemSize: itemSize]; if (freeWhenDone) - free(items); + OFFreeMemory(items); return self; } - (instancetype)initWithStringRepresentation: (OFString *)string @@ -179,11 +179,11 @@ { if (SIZE_MAX - _count < 1) @throw [OFOutOfRangeException exception]; if (_count + 1 > _capacity) { - _items = of_realloc(_items, _count + 1, _itemSize); + _items = OFResizeMemory(_items, _count + 1, _itemSize); _capacity = _count + 1; } memcpy(_items + _count * _itemSize, item, _itemSize); @@ -199,11 +199,11 @@ { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = of_realloc(_items, _count + count, _itemSize); + _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memcpy(_items + _count * _itemSize, items, count * _itemSize); _count += count; @@ -215,11 +215,11 @@ { if (count > SIZE_MAX - _count || idx > _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = of_realloc(_items, _count + count, _itemSize); + _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memmove(_items + (idx + count) * _itemSize, _items + idx * _itemSize, (_count - idx) * _itemSize); @@ -232,11 +232,11 @@ { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { - _items = of_realloc(_items, _count + count, _itemSize); + _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; @@ -257,11 +257,11 @@ _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize); _count -= range.length; @try { - _items = of_realloc(_items, _count, _itemSize); + _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -271,20 +271,20 @@ if (_count == 0) return; _count--; @try { - _items = of_realloc(_items, _count, _itemSize); + _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { - free(_items); + OFFreeMemory(_items); _items = NULL; _count = 0; _capacity = 0; } @@ -297,15 +297,15 @@ - (void)makeImmutable { if (_capacity != _count) { @try { - _items = of_realloc(_items, _count, _itemSize); + _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } object_setClass(self, [OFData class]); } @end Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -166,11 +166,11 @@ { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; - cArray = of_alloc(count, sizeof(id)); + cArray = OFAllocMemory(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { @@ -180,11 +180,11 @@ for (i = 0; i < count; i++) if (![set containsObject: cArray[i]]) [self removeObject: cArray[i]]; } @finally { - free(cArray); + OFFreeMemory(cArray); } objc_autoreleasePoolPop(pool); } Index: src/OFMutableUTF8String.m ================================================================== --- src/OFMutableUTF8String.m +++ src/OFMutableUTF8String.m @@ -44,11 +44,11 @@ freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String @@ -56,11 +56,11 @@ freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return self; } #ifdef OF_HAVE_UNICODE_TABLES @@ -97,11 +97,11 @@ return; } unicodeLen = self.length; - unicodeString = of_alloc(unicodeLen, sizeof(OFUnichar)); + unicodeString = OFAllocMemory(unicodeLen, sizeof(OFUnichar)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { @@ -120,11 +120,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { - free(unicodeString); + OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = of_ascii_isspace(c); @@ -143,21 +143,21 @@ else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { - free(unicodeString); + OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { - newCString = of_alloc(newCStringLength + 1, 1); + newCString = OFAllocMemory(newCStringLength + 1, 1); } @catch (id e) { - free(unicodeString); + OFFreeMemory(unicodeString); @throw e; } j = 0; @@ -164,22 +164,22 @@ for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { - free(unicodeString); - free(newCString); + OFFreeMemory(unicodeString); + OFFreeMemory(newCString); @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; - free(unicodeString); + OFFreeMemory(unicodeString); - free(_s->cString); + OFFreeMemory(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* @@ -220,11 +220,11 @@ _s->hashed = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength - lenOld + lenNew + 1, 1); memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); @@ -246,11 +246,11 @@ if (character >= 0x80) _s->isUTF8 = true; @try { - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -274,11 +274,11 @@ case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength + 1); _s->cStringLength += UTF8StringLength; @@ -303,11 +303,11 @@ case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += length; @@ -349,11 +349,11 @@ @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, string.UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; @@ -367,14 +367,13 @@ _s->isUTF8 = true; } else _s->isUTF8 = true; } -- (void)appendCharacters: (const OFUnichar *)characters - length: (size_t)length +- (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { - char *tmp = of_alloc((length * 4) + 1, 1); + char *tmp = OFAllocMemory((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; @@ -392,21 +391,21 @@ } tmp[j] = '\0'; _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + j + 1, 1); memcpy(_s->cString + _s->cStringLength, tmp, j + 1); _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { - free(tmp); + OFFreeMemory(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { @@ -518,11 +517,11 @@ idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hashed = false; - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + idx + string.UTF8StringLength, _s->cString + idx, _s->cStringLength - idx); memcpy(_s->cString + idx, string.UTF8String, string.UTF8StringLength); @@ -560,11 +559,12 @@ _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -601,11 +601,12 @@ * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, + 1); memmove(_s->cString + start + replacement.UTF8StringLength, _s->cString + end, _s->cStringLength - end); memcpy(_s->cString + start, replacement.UTF8String, replacement.UTF8StringLength); @@ -614,11 +615,12 @@ /* * If the new string is smaller, we can safely resize it now as we're * done with memmove(). */ if (newCStringLength < _s->cStringLength) - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, + 1); _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || @@ -667,15 +669,15 @@ for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { - newCString = of_realloc(newCString, + newCString = OFResizeMemory(newCString, newCStringLength + i - last + replacementLength + 1, 1); } @catch (id e) { - free(newCString); + OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, @@ -687,22 +689,22 @@ i += searchLength - 1; last = i + 1; } @try { - newCString = of_realloc(newCString, + newCString = OFResizeMemory(newCString, newCStringLength + _s->cStringLength - last + 1, 1); } @catch (id e) { - free(newCString); + OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, _s->cStringLength - last); newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; - free(_s->cString); + OFFreeMemory(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; @@ -728,11 +730,12 @@ memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -754,11 +757,12 @@ _s->cStringLength -= d; _s->length -= d; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -790,11 +794,12 @@ memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } Index: src/OFObject+KeyValueCoding.m ================================================================== --- src/OFObject+KeyValueCoding.m +++ src/OFObject+KeyValueCoding.m @@ -46,21 +46,21 @@ if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } - name = of_alloc(keyLength + 3, 1); + name = OFAllocMemory(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; name[2] = of_ascii_toupper(name[2]); selector = sel_registerName(name); } @finally { - free(name); + OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == NULL) { @@ -155,21 +155,21 @@ objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } - name = of_alloc(keyLength + 5, 1); + name = OFAllocMemory(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); name[3] = of_ascii_toupper(name[3]); selector = sel_registerName(name); } @finally { - free(name); + OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == nil || Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -1242,44 +1242,44 @@ #endif /** * @brief Allocates memory for the specified number of items of the specified * size. * - * To free the allocated memory, use `free()`. + * To free the allocated memory, use @ref OFFreeMemory. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. * * @param count The number of items to allocate * @param size The size of each item to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ -extern void *_Nullable of_alloc(size_t count, size_t size) +extern void *_Nullable OFAllocMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Allocates memory for the specified number of items of the specified * size and initializes it with zeros. * - * To free the allocated memory, use `free()`. + * To free the allocated memory, use @ref OFFreeMemory. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. * * @param size The size of each item to allocate * @param count The number of items to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ -extern void *_Nullable of_alloc_zeroed(size_t count, size_t size) +extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Resizes memory to the specified number of items of the specified size. * - * To free the allocated memory, use `free()`. + * To free the allocated memory, use @ref OFFreeMemory. * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. * * Throws @ref OFOutOfMemoryException if allocating failed and @@ -1288,13 +1288,22 @@ * @param pointer A pointer to the already allocated memory * @param size The size of each item to resize to * @param count The number of items to resize to * @return A pointer to the resized memory chunk */ -extern void *_Nullable of_realloc(void *_Nullable pointer, size_t count, +extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count, size_t size) OF_WARN_UNUSED_RESULT; +/** + * @brief Frees memory allocated by @ref OFAllocMemory, @ref OFAllocZeroedMemory + * or @ref OFResizeMemory. + * + * @param pointer A pointer to the memory to free or nil (passing nil ooes + * nothing) + */ +extern void OFFreeMemory(void *_Nullable pointer); + #ifdef OF_APPLE_RUNTIME extern void *_Null_unspecified objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); # ifndef __OBJC2__ extern id _Nullable objc_constructInstance(Class _Nullable class_, Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -95,11 +95,11 @@ } allocFailedException; uint32_t of_hash_seed; void * -of_alloc(size_t count, size_t size) +OFAllocMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; @@ -113,11 +113,11 @@ return pointer; } void * -of_alloc_zeroed(size_t count, size_t size) +OFAllocZeroedMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; @@ -132,11 +132,11 @@ return pointer; } void * -of_realloc(void *pointer, size_t count, size_t size) +OFResizeMemory(void *pointer, size_t count, size_t size) { if OF_UNLIKELY (count == 0 || size == 0) return NULL; if OF_UNLIKELY (count > SIZE_MAX / size) @@ -146,10 +146,16 @@ @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } + +void +OFFreeMemory(void *pointer) +{ + free(pointer); +} #if !defined(HAVE_ARC4RANDOM) && !defined(HAVE_GETRANDOM) static void initRandom(void) { Index: src/OFOptionsParser.m ================================================================== --- src/OFOptionsParser.m +++ src/OFOptionsParser.m @@ -82,11 +82,11 @@ *iter->argumentPtr = nil; count++; } - _options = of_alloc(count + 1, sizeof(*_options)); + _options = OFAllocMemory(count + 1, sizeof(*_options)); _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions]; for (iter = options, iter2 = _options; @@ -144,11 +144,11 @@ for (OFOptionsParserOption *iter = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++) [iter->longOption release]; - free(_options); + OFFreeMemory(_options); [_longOptions release]; [_arguments release]; [_argument release]; Index: src/OFPollKernelEventObserver.m ================================================================== --- src/OFPollKernelEventObserver.m +++ src/OFPollKernelEventObserver.m @@ -48,11 +48,11 @@ _FDs = [[OFMutableData alloc] initWithItemSize: sizeof(struct pollfd)]; [_FDs addItem: &p]; _maxFD = _cancelFD[0]; - _FDToObject = of_alloc((size_t)_maxFD + 1, sizeof(id)); + _FDToObject = OFAllocMemory((size_t)_maxFD + 1, sizeof(id)); } @catch (id e) { [self release]; @throw e; } @@ -60,11 +60,11 @@ } - (void)dealloc { [_FDs release]; - free(_FDToObject); + OFFreeMemory(_FDToObject); [super dealloc]; } static void @@ -93,11 +93,11 @@ if (!found) { struct pollfd p = { fd, events, 0 }; if (fd > self->_maxFD) { self->_maxFD = fd; - self->_FDToObject = of_realloc(self->_FDToObject, + self->_FDToObject = OFResizeMemory(self->_FDToObject, (size_t)self->_maxFD + 1, sizeof(id)); } self->_FDToObject[fd] = object; [self->_FDs addItem: &p]; Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -125,11 +125,11 @@ # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { - free(preallocatedPages); + OFFreeMemory(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif @@ -137,22 +137,22 @@ return page; } } - page = of_alloc(1, sizeof(*page)); + page = OFAllocMemory(1, sizeof(*page)); @try { - page->map = of_alloc_zeroed(1, mapSize); + page->map = OFAllocZeroedMemory(1, mapSize); } @catch (id e) { - free(page); + OFFreeMemory(page); @throw e; } @try { page->page = mapPages(1); } @catch (id e) { - free(page->map); - free(page); + OFFreeMemory(page->map); + OFFreeMemory(page); @throw e; } of_explicit_memset(page->page, 0, pageSize); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) @@ -191,11 +191,11 @@ for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; unmapPages(page->page, 1); - free(page->map); + OFFreeMemory(page->map); if (page->previous != NULL) page->previous->next = page->next; if (page->next != NULL) page->next->previous = page->previous; @@ -210,11 +210,11 @@ OF_ENSURE(OFTLSKeySet(firstPageKey, page->next) == 0); if (OFTLSKeyGet(lastPageKey) == page) OF_ENSURE(OFTLSKeySet(lastPageKey, page->previous) == 0); # endif - free(page); + OFFreeMemory(page); } static void * allocateMemory(struct page *page, size_t bytes) { @@ -292,11 +292,11 @@ size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; - preallocatedPages = of_alloc_zeroed(numPages, sizeof(struct page)); + preallocatedPages = OFAllocZeroedMemory(numPages, sizeof(struct page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_ENSURE(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif @try { @@ -304,11 +304,11 @@ preallocatedPages[i] = addPage(false); } @catch (id e) { for (size_t j = 0; j < i; j++) removePageIfEmpty(preallocatedPages[j]); - free(preallocatedPages); + OFFreeMemory(preallocatedPages); preallocatedPages = NULL; @throw e; } @@ -413,11 +413,11 @@ if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { - _items = of_alloc(count, itemSize); + _items = OFAllocMemory(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, Index: src/OFSeekableStream.m ================================================================== --- src/OFSeekableStream.m +++ src/OFSeekableStream.m @@ -48,12 +48,12 @@ if (whence == SEEK_CUR) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return offset; } @end Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -91,12 +91,12 @@ return self; } - (void)dealloc { - free(_readBufferMemory); - free(_writeBuffer); + OFFreeMemory(_readBufferMemory); + OFFreeMemory(_writeBuffer); [super dealloc]; } - (bool)lowlevelIsAtEndOfStream @@ -144,11 +144,12 @@ length: MIN_READ_SIZE]; if (bytesRead > length) { memcpy(buffer, tmp, length); - readBuffer = of_alloc(bytesRead - length, 1); + readBuffer = OFAllocMemory(bytesRead - length, + 1); memcpy(readBuffer, tmp + length, bytesRead - length); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bytesRead - length; @@ -165,11 +166,11 @@ if (length >= _readBufferLength) { size_t ret = _readBufferLength; memcpy(buffer, _readBuffer, _readBufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return ret; } else { @@ -582,19 +583,19 @@ char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; - buffer = of_alloc(count, itemSize); + buffer = OFAllocMemory(count, itemSize); @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer count: count itemSize: itemSize freeWhenDone: true]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } return ret; } @@ -601,20 +602,20 @@ - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = of_alloc(1, pageSize); + char *buffer = OFAllocMemory(1, pageSize); @try { while (!self.atEndOfStream) { size_t length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { - free(buffer); + OFFreeMemory(buffer); } [data makeImmutable]; return data; } @@ -627,18 +628,18 @@ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding { OFString *ret; - char *buffer = of_alloc(length + 1, 1); + char *buffer = OFAllocMemory(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } @@ -671,11 +672,11 @@ } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; @@ -691,11 +692,11 @@ ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; @@ -707,11 +708,11 @@ /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; - char *retCString = of_alloc(retLength, 1); + char *retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, @@ -730,38 +731,39 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_alloc( + readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { - free(retCString); + OFFreeMemory(retCString); } - readBuffer = of_alloc(bufferLength - i - 1, 1); + readBuffer = OFAllocMemory(bufferLength - i - 1, + 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; @@ -768,23 +770,23 @@ } } /* There was no newline or \0 */ if (bufferLength > 0) { - readBuffer = of_alloc(_readBufferLength + bufferLength, - 1); + readBuffer = OFAllocMemory( + _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - free(buffer); + OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } @@ -909,11 +911,11 @@ } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = of_alloc(1, pageSize); + buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; @@ -922,11 +924,11 @@ ret = [OFString stringWithCString: _readBuffer encoding: encoding length: _readBufferLength]; - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; @@ -947,11 +949,11 @@ if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; - retCString = of_alloc(retLength, 1); + retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); @@ -971,38 +973,39 @@ if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ - readBuffer = of_alloc( + readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { - free(retCString); + OFFreeMemory(retCString); } - readBuffer = of_alloc(bufferLength - i - 1, 1); + readBuffer = OFAllocMemory(bufferLength - i - 1, + 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; @@ -1009,23 +1012,23 @@ } } /* Neither the delimiter nor \0 was found */ if (bufferLength > 0) { - readBuffer = of_alloc(_readBufferLength + bufferLength, - 1); + readBuffer = OFAllocMemory( + _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - free(buffer); + OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } @@ -1061,11 +1064,11 @@ if (_writeBuffer == NULL) return; [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; - free(_writeBuffer); + OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; } - (size_t)writeBuffer: (const void *)buffer @@ -1082,11 +1085,11 @@ bytesWritten: bytesWritten errNo: 0]; return bytesWritten; } else { - _writeBuffer = of_realloc(_writeBuffer, + _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength + length, 1); memcpy(_writeBuffer + _writeBufferLength, buffer, length); _writeBufferLength += length; return length; @@ -1249,19 +1252,19 @@ size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); + uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1276,19 +1279,19 @@ size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); + uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1303,19 +1306,19 @@ size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); + uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1330,19 +1333,19 @@ size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_alloc(count, sizeof(float)); + float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1357,19 +1360,19 @@ size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_alloc(count, sizeof(double)); + double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1414,19 +1417,19 @@ size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = of_alloc(count, sizeof(uint16_t)); + uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1441,19 +1444,19 @@ size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = of_alloc(count, sizeof(uint32_t)); + uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1468,19 +1471,19 @@ size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = of_alloc(count, sizeof(uint64_t)); + uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1495,19 +1498,19 @@ size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = of_alloc(count, sizeof(float)); + float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1522,19 +1525,19 @@ size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = of_alloc(count, sizeof(double)); + double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - free(tmp); + OFFreeMemory(tmp); } #endif return size; } @@ -1589,20 +1592,20 @@ - (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; - buffer = of_alloc(stringLength + 1, 1); + buffer = OFAllocMemory(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return stringLength + 1; } @@ -1739,28 +1742,28 @@ char *readBuffer; if (length > SIZE_MAX - _readBufferLength) @throw [OFOutOfRangeException exception]; - readBuffer = of_alloc(_readBufferLength + length, 1); + readBuffer = OFAllocMemory(_readBufferLength + length, 1); memcpy(readBuffer, buffer, length); memcpy(readBuffer + length, _readBuffer, _readBufferLength); - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += length; } - (void)close { - free(_readBufferMemory); + OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; - free(_writeBuffer); + OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; _buffersWrites = false; _waitingForDelimiter = false; } @end Index: src/OFString+JSONParsing.m ================================================================== --- src/OFString+JSONParsing.m +++ src/OFString+JSONParsing.m @@ -148,17 +148,17 @@ char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; - buffer = of_alloc(stop - *pointer, 1); + buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { - free(buffer); + OFFreeMemory(buffer); return nil; } switch (**pointer) { case '"': @@ -193,26 +193,26 @@ OFUnichar c; size_t l; c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { - free(buffer); + OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { - free(buffer); + OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = of_string_utf8_encode(c1, buffer + i); if (l == 0) { - free(buffer); + OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; @@ -225,20 +225,20 @@ * surrogate and now need to get the other one * in order to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { - free(buffer); + OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = of_string_utf8_encode(c, buffer + i); if (l == 0) { - free(buffer); + OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; @@ -256,11 +256,11 @@ case '\n': (*pointer)++; (*line)++; break; default: - free(buffer); + OFFreeMemory(buffer); return nil; } /* End of string found */ } else if (**pointer == delimiter) { OFString *ret; @@ -267,38 +267,38 @@ @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { - free(buffer); + OFFreeMemory(buffer); } (*pointer)++; return ret; /* Newlines in strings are disallowed */ } else if (**pointer == '\n' || **pointer == '\r') { (*line)++; - free(buffer); + OFFreeMemory(buffer); return nil; } else { buffer[i++] = **pointer; (*pointer)++; } } - free(buffer); + OFFreeMemory(buffer); return nil; } static inline OFString * parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; - buffer = of_alloc(stop - *pointer, 1); + buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || @@ -310,31 +310,31 @@ OFChar16 c1, c2; OFUnichar c; size_t l; if (++(*pointer) >= stop || **pointer != 'u') { - free(buffer); + OFFreeMemory(buffer); return nil; } c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { - free(buffer); + OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { - free(buffer); + OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = of_string_utf8_encode(c1, buffer + i); if (l == 0) { - free(buffer); + OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; @@ -347,37 +347,37 @@ * surrogate and now need to get the other one in order * to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { - free(buffer); + OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = of_string_utf8_encode(c, buffer + i); if (l == 0) { - free(buffer); + OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; } else { OFString *ret; if (i == 0 || (buffer[0] >= '0' && buffer[0] <= '9')) { - free(buffer); + OFFreeMemory(buffer); return nil; } @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { - free(buffer); + OFFreeMemory(buffer); } return ret; } } @@ -384,11 +384,11 @@ /* * It is never possible to end with an identifier, thus we should never * reach stop. */ - free(buffer); + OFFreeMemory(buffer); return nil; } static inline OFMutableArray * parseArray(const char **pointer, const char *stop, size_t *line, Index: src/OFString+URLEncoding.m ================================================================== --- src/OFString+URLEncoding.m +++ src/OFString+URLEncoding.m @@ -83,11 +83,11 @@ char *retCString; char byte = 0; int state = 0; size_t i = 0; - retCString = of_alloc(length + 1, 1); + retCString = OFAllocMemory(length + 1, 1); while (length--) { char c = *string++; switch (state) { @@ -106,11 +106,11 @@ else if (c >= 'A' && c <= 'F') byte += (c - 'A' + 10) << shift; else if (c >= 'a' && c <= 'f') byte += (c - 'a' + 10) << shift; else { - free(retCString); + OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } if (++state == 3) { retCString[i++] = byte; @@ -124,25 +124,25 @@ retCString[i] = '\0'; objc_autoreleasePoolPop(pool); if (state != 0) { - free(retCString); + OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } @try { - retCString = of_realloc(retCString, 1, i + 1); + retCString = OFResizeMemory(retCString, 1, i + 1); } @catch (OFOutOfMemoryException *e) { /* We don't care if it fails, as we only made it smaller. */ } @try { return [OFString stringWithUTF8StringNoCopy: retCString length: i freeWhenDone: true]; } @catch (id e) { - free(retCString); + OFFreeMemory(retCString); @throw e; } } @end Index: src/OFString+XMLEscaping.m ================================================================== --- src/OFString+XMLEscaping.m +++ src/OFString+XMLEscaping.m @@ -38,11 +38,11 @@ string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; - retCString = of_alloc(retLength, 1); + retCString = OFAllocMemory(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; @@ -73,14 +73,14 @@ appendLen = 0; } if (append != NULL) { @try { - retCString = of_realloc(retCString, 1, + retCString = OFResizeMemory(retCString, 1, retLength + appendLen); } @catch (id e) { - free(retCString); + OFFreeMemory(retCString); @throw e; } retLength += appendLen - 1; memcpy(retCString + j, append, appendLen); @@ -94,10 +94,10 @@ @try { ret = [OFString stringWithUTF8String: retCString length: retLength]; } @finally { - free(retCString); + OFFreeMemory(retCString); } return ret; } @end Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -833,11 +833,11 @@ freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String @@ -845,11 +845,11 @@ freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithCString: (const char *)cString @@ -1013,17 +1013,17 @@ * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; - tmp = of_alloc((size_t)fileSize + 1, 1); + tmp = OFAllocMemory((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp exactLength: (size_t)fileSize]; } @catch (id e) { - free(tmp); + OFFreeMemory(tmp); @throw e; } @finally { [file release]; } @@ -1037,20 +1037,20 @@ @try { self = [self initWithUTF8StringNoCopy: tmp length: (size_t)fileSize freeWhenDone: true]; } @catch (id e) { - free(tmp); + OFFreeMemory(tmp); @throw e; } } else { @try { self = [self initWithCString: tmp encoding: encoding length: (size_t)fileSize]; } @finally { - free(tmp); + OFFreeMemory(tmp); } } return self; } @@ -1372,25 +1372,25 @@ char *cString; size_t cStringLength; switch (encoding) { case OFStringEncodingUTF8: - cString = of_alloc((length * 4) + 1, 1); + cString = OFAllocMemory((length * 4) + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: (length * 4) + 1 encoding: OFStringEncodingUTF8 lossy: lossy]; } @catch (id e) { - free(cString); + OFFreeMemory(cString); @throw e; } @try { - cString = of_realloc(cString, cStringLength + 1, 1); + cString = OFResizeMemory(cString, cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } break; @@ -1405,19 +1405,19 @@ case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: - cString = of_alloc(length + 1, 1); + cString = OFAllocMemory(length + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: length + 1 encoding: encoding lossy: lossy]; } @catch (id e) { - free(cString); + OFFreeMemory(cString); @throw e; } break; default: @@ -1427,11 +1427,11 @@ @try { return [[OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true] items]; } @catch (id e) { - free(cString); + OFFreeMemory(cString); @throw e; } } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding @@ -1836,11 +1836,11 @@ pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; - characters = of_alloc(range.length, sizeof(OFUnichar)); + characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { @@ -1865,11 +1865,11 @@ searchLength); } } } } @finally { - free(characters); + OFFreeMemory(characters); } objc_autoreleasePoolPop(pool); return OFRangeMake(OFNotFound, 0); @@ -1903,11 +1903,11 @@ return OFNotFound; if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; - characters = of_alloc(range.length, sizeof(OFUnichar)); + characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - 1;; i--) { @@ -1926,11 +1926,11 @@ @selector(characterIsMember:), characters[i])) return range.location + i; } } @finally { - free(characters); + OFFreeMemory(characters); } return OFNotFound; } @@ -2111,11 +2111,11 @@ bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; - tmp = of_alloc(prefixLength, sizeof(OFUnichar)); + tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFRangeMake(0, prefixLength)]; @@ -2122,11 +2122,11 @@ hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { - free(tmp); + OFFreeMemory(tmp); } return hasPrefix; } @@ -2140,11 +2140,11 @@ if ((suffixLength = suffix.length) > self.length) return false; length = self.length; - tmp = of_alloc(suffixLength, sizeof(OFUnichar)); + tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFRangeMake(length - suffixLength, @@ -2154,11 +2154,11 @@ hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { - free(tmp); + OFFreeMemory(tmp); } return hasSuffix; } @@ -2530,20 +2530,20 @@ - (const OFUnichar *)characters { size_t length = self.length; OFUnichar *buffer; - buffer = of_alloc(length, sizeof(OFUnichar)); + buffer = OFAllocMemory(length, sizeof(OFUnichar)); @try { [self getCharacters: buffer inRange: OFRangeMake(0, length)]; return [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } } - (const OFChar16 *)UTF16String @@ -2559,18 +2559,18 @@ OFChar16 *buffer; size_t j; bool swap = (byteOrder != OFByteOrderNative); /* Allocate memory for the worst case */ - buffer = of_alloc((length + 1) * 2, sizeof(OFChar16)); + buffer = OFAllocMemory((length + 1) * 2, sizeof(OFChar16)); j = 0; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (c > 0x10FFFF) { - free(buffer); + OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (swap) { if (c > 0xFFFF) { @@ -2589,11 +2589,11 @@ } } buffer[j] = 0; @try { - buffer = of_realloc(buffer, j + 1, sizeof(OFChar16)); + buffer = OFResizeMemory(buffer, j + 1, sizeof(OFChar16)); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @@ -2602,11 +2602,11 @@ return [[OFData dataWithItemsNoCopy: buffer count: j + 1 itemSize: sizeof(OFChar16) freeWhenDone: true] items]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } } - (size_t)UTF16StringLength @@ -2631,11 +2631,11 @@ - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { size_t length = self.length; OFChar32 *buffer; - buffer = of_alloc(length + 1, sizeof(OFChar32)); + buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { [self getCharacters: buffer inRange: OFRangeMake(0, length)]; buffer[length] = 0; if (byteOrder != OFByteOrderNative) @@ -2645,11 +2645,11 @@ return [[OFData dataWithItemsNoCopy: buffer count: length + 1 itemSize: sizeof(OFChar32) freeWhenDone: true] items]; } @catch (id e) { - free(buffer); + OFFreeMemory(buffer); @throw e; } } - (OFData *)dataWithEncoding: (OFStringEncoding)encoding Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -608,11 +608,11 @@ objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @finally { - free(UTF8String2); + OFFreeMemory(UTF8String2); } return self; } @@ -702,11 +702,11 @@ objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @finally { - free(UTF8String2); + OFFreeMemory(UTF8String2); } return self; } Index: src/OFUTF8String.m ================================================================== --- src/OFUTF8String.m +++ src/OFUTF8String.m @@ -177,11 +177,11 @@ self = [super init]; @try { _s = &_storage; - _s->cString = of_alloc_zeroed(1, 1); + _s->cString = OFAllocZeroedMemory(1, 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } @@ -243,11 +243,11 @@ cStringLength -= 3; } _s = &_storage; - _s->cString = of_alloc(cStringLength + 1, 1); + _s->cString = OFAllocMemory(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OFStringEncodingUTF8 || encoding == OFStringEncodingASCII) { @@ -291,11 +291,11 @@ if (bytes == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += bytes - 1; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, bytes); j += bytes; } @@ -371,11 +371,11 @@ if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, byteLength); j += byteLength; } @@ -448,11 +448,11 @@ else _s->isUTF8 = true; _s->length = string.length; - _s->cString = of_alloc(_s->cStringLength + 1, 1); + _s->cString = OFAllocMemory(_s->cStringLength + 1, 1); memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; @@ -469,11 +469,11 @@ @try { size_t j; _s = &_storage; - _s->cString = of_alloc((length * 4) + 1, 1); + _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -491,11 +491,11 @@ _s->cString[j] = '\0'; _s->cStringLength = j; @try { - _s->cString = of_realloc(_s->cString, j + 1, 1); + _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -525,11 +525,11 @@ } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; - _s->cString = of_alloc((length * 4) + 1, 1); + _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -576,11 +576,11 @@ _s->cString[j] = '\0'; _s->cStringLength = j; @try { - _s->cString = of_realloc(_s->cString, j + 1, 1); + _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -610,11 +610,11 @@ } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; - _s->cString = of_alloc((length * 4) + 1, 1); + _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { @@ -643,11 +643,11 @@ _s->cString[j] = '\0'; _s->cStringLength = j; @try { - _s->cString = of_realloc(_s->cString, j + 1, 1); + _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -685,15 +685,15 @@ break; case -1: @throw [OFInvalidEncodingException exception]; } - _s->cString = of_alloc(cStringLength + 1, 1); + _s->cString = OFAllocMemory(cStringLength + 1, 1); memcpy(_s->cString, tmp, cStringLength + 1); _s->freeWhenDone = true; } @finally { - free(tmp); + OFFreeMemory(tmp); } } @catch (id e) { [self release]; @throw e; } @@ -702,11 +702,11 @@ } - (void)dealloc { if (_s != NULL && _s->freeWhenDone) - free(_s->cString); + OFFreeMemory(_s->cString); [super dealloc]; } - (size_t)getCString: (char *)cString @@ -1152,11 +1152,11 @@ return array; } - (const OFUnichar *)characters { - OFUnichar *buffer = of_alloc(_s->length, sizeof(OFUnichar)); + OFUnichar *buffer = OFAllocMemory(_s->length, sizeof(OFUnichar)); size_t i = 0, j = 0; while (i < _s->cStringLength) { OFUnichar c; ssize_t cLen; @@ -1163,11 +1163,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { - free(buffer); + OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } buffer[j++] = c; i += cLen; @@ -1179,11 +1179,11 @@ freeWhenDone: true] items]; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { - OFChar32 *buffer = of_alloc(_s->length + 1, sizeof(OFChar32)); + OFChar32 *buffer = OFAllocMemory(_s->length + 1, sizeof(OFChar32)); size_t i = 0, j = 0; while (i < _s->cStringLength) { OFChar32 c; ssize_t cLen; @@ -1190,11 +1190,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { - free(buffer); + OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (byteOrder != OFByteOrderNative) buffer[j++] = OF_BSWAP32(c); Index: src/OFValue.m ================================================================== --- src/OFValue.m +++ src/OFValue.m @@ -97,25 +97,25 @@ if (strcmp([object objCType], objCType) != 0) return false; size = of_sizeof_type_encoding(objCType); - value = of_alloc(1, size); + value = OFAllocMemory(1, size); @try { - otherValue = of_alloc(1, size); + otherValue = OFAllocMemory(1, size); } @catch (id e) { - free(value); + OFFreeMemory(value); @throw e; } @try { [self getValue: value size: size]; [object getValue: otherValue size: size]; ret = (memcmp(value, otherValue, size) == 0); } @finally { - free(value); - free(otherValue); + OFFreeMemory(value); + OFFreeMemory(otherValue); } return ret; } @@ -123,11 +123,11 @@ { size_t size = of_sizeof_type_encoding(self.objCType); unsigned char *value; uint32_t hash; - value = of_alloc(1, size); + value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; OF_HASH_INIT(hash); @@ -134,11 +134,11 @@ for (size_t i = 0; i < size; i++) OF_HASH_ADD(hash, value[i]); OF_HASH_FINALIZE(hash); } @finally { - free(value); + OFFreeMemory(value); } return hash; } @@ -204,11 +204,11 @@ OFMutableString *ret = [OFMutableString stringWithString: @" 0) @@ -215,14 +215,14 @@ [ret appendString: @" "]; [ret appendFormat: @"%02x", value[i]]; } } @finally { - free(value); + OFFreeMemory(value); } [ret appendString: @">"]; [ret makeImmutable]; return ret; } @end Index: src/OFWin32ConsoleStdIOStream.m ================================================================== --- src/OFWin32ConsoleStdIOStream.m +++ src/OFWin32ConsoleStdIOStream.m @@ -132,11 +132,11 @@ size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; - UTF16 = of_alloc(length, sizeof(OFChar16)); + UTF16 = OFAllocMemory(length, sizeof(OFChar16)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; @@ -251,11 +251,11 @@ } if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { - free(UTF16); + OFFreeMemory(UTF16); } objc_autoreleasePoolPop(pool); return j; @@ -355,11 +355,11 @@ _incompleteUTF8SurrogateLen = 0; i += toCopy; } - tmp = of_alloc(length * 2, sizeof(OFChar16)); + tmp = OFAllocMemory(length * 2, sizeof(OFChar16)); @try { DWORD bytesWritten; while (i < length) { OFUnichar c; @@ -434,11 +434,11 @@ exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { - free(tmp); + OFFreeMemory(tmp); } /* * We do not count in bytes when writing to the Win32 console. But * since any incomplete write is an exception here anyway, we can just Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -114,19 +114,19 @@ level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { - char *whitespaces = of_alloc((level * indentation) + 1, 1); + char *whitespaces = OFAllocMemory((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s", whitespaces, _text]; } @finally { - free(whitespaces); + OFFreeMemory(whitespaces); } } else ret = [OFString stringWithFormat: @"", _text]; return ret; Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -450,11 +450,11 @@ else defaultNS = _defaultNamespace; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); - cString = of_alloc(length, 1); + cString = OFAllocMemory(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; @@ -461,11 +461,11 @@ /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += prefix.UTF8StringLength + 1; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; @@ -477,11 +477,11 @@ /* xmlns if necessary */ if (prefix == nil && ((_namespace != nil && ![_namespace isEqual: defaultNS]) || (_namespace == nil && defaultNS != nil))) { length += _namespace.UTF8StringLength + 9; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); @@ -510,11 +510,11 @@ element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); cString[i++] = ' '; if (attributePrefix != nil) { memcpy(cString + i, attributePrefix.UTF8String, attributePrefix.UTF8StringLength); @@ -580,11 +580,11 @@ if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); cString[i++] = '>'; memcpy(cString + i, tmp.items, tmp.count); i += tmp.count; @@ -596,11 +596,11 @@ cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += prefix.UTF8StringLength + 1; - cString = of_realloc(cString, length, 1); + cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; @@ -617,11 +617,11 @@ objc_autoreleasePoolPop(pool); ret = [OFString stringWithUTF8String: cString length: length]; } @finally { - free(cString); + OFFreeMemory(cString); } return ret; } - (OFString *)XMLString Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -270,20 +270,20 @@ } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = of_alloc(1, pageSize); + char *buffer = OFAllocMemory(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; [self parseBuffer: buffer length: length]; } } @finally { - free(buffer); + OFFreeMemory(buffer); } } static void inByteOrderMarkState(OFXMLParser *self) Index: src/OFXMLProcessingInstruction.m ================================================================== --- src/OFXMLProcessingInstruction.m +++ src/OFXMLProcessingInstruction.m @@ -142,11 +142,11 @@ - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { if (indentation > 0 && level > 0) { OFString *ret; - char *whitespaces = of_alloc((level * indentation) + 1, 1); + char *whitespaces = OFAllocMemory((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { if (_data.length > 0) @@ -155,11 +155,11 @@ _target, _data]; else ret = [OFString stringWithFormat: @"%s", whitespaces, _target]; } @finally { - free(whitespaces); + OFFreeMemory(whitespaces); } return ret; } else return self.XMLString; Index: src/huffman_tree.m ================================================================== --- src/huffman_tree.m +++ src/huffman_tree.m @@ -26,11 +26,11 @@ static struct of_huffman_tree * newTree(void) { struct of_huffman_tree *tree; - tree = of_alloc(1, sizeof(*tree)); + tree = OFAllocMemory(1, sizeof(*tree)); tree->leaves[0] = tree->leaves[1] = NULL; tree->value = 0xFFFF; return tree; } @@ -65,13 +65,13 @@ @try { for (uint16_t i = 0; i < count; i++) { uint_fast8_t length = lengths[i]; if OF_UNLIKELY (length > maxBit) { - lengthCount = of_realloc(lengthCount, + lengthCount = OFResizeMemory(lengthCount, length + 1, sizeof(uint16_t)); - nextCode = of_realloc(nextCode, + nextCode = OFResizeMemory(nextCode, length + 1, sizeof(uint16_t)); for (uint_fast8_t j = maxBit + 1; j <= length; j++) { lengthCount[j] = 0; @@ -100,12 +100,12 @@ if (length > 0) insertTree(tree, nextCode[length]++, length, i); } } @finally { - free(lengthCount); - free(nextCode); + OFFreeMemory(lengthCount); + OFFreeMemory(nextCode); } return tree; } @@ -124,7 +124,7 @@ { for (uint_fast8_t i = 0; i < 2; i++) if OF_LIKELY (tree->leaves[i] != NULL) of_huffman_tree_release(tree->leaves[i]); - free(tree); + OFFreeMemory(tree); } Index: src/platform/posix/OFSubprocess.m ================================================================== --- src/platform/posix/OFSubprocess.m +++ src/platform/posix/OFSubprocess.m @@ -205,16 +205,16 @@ } @finally { char **iter; close(_readPipe[1]); close(_writePipe[0]); - free(argv); + OFFreeMemory(argv); for (iter = env; *iter != NULL; iter++) - free(*iter); + OFFreeMemory(*iter); - free(env); + OFFreeMemory(env); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @@ -238,11 +238,11 @@ { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; OFStringEncoding encoding; - *argv = of_alloc(count + 2, sizeof(char *)); + *argv = OFAllocMemory(count + 2, sizeof(char *)); encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; @@ -263,11 +263,11 @@ return NULL; encoding = [OFLocale encoding]; count = environment.count; - envp = of_alloc_zeroed(count + 1, sizeof(char *)); + envp = OFAllocZeroedMemory(count + 1, sizeof(char *)); @try { OFEnumerator *keyEnumerator = [environment keyEnumerator]; OFEnumerator *objectEnumerator = [environment objectEnumerator]; @@ -281,11 +281,11 @@ keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; - envp[i] = of_alloc(keyLen + objectLen + 2, 1); + envp[i] = OFAllocMemory(keyLen + objectLen + 2, 1); memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, @@ -292,13 +292,13 @@ [object cStringWithEncoding: encoding], objectLen); envp[i][keyLen + objectLen + 1] = '\0'; } } @catch (id e) { for (size_t i = 0; i < count; i++) - free(envp[i]); + OFFreeMemory(envp[i]); - free(envp); + OFFreeMemory(envp); @throw e; } return envp; Index: src/platform/windows/OFSubprocess.m ================================================================== --- src/platform/windows/OFSubprocess.m +++ src/platform/windows/OFSubprocess.m @@ -191,11 +191,11 @@ si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; - argumentsCopy = of_alloc(length + 1, + argumentsCopy = OFAllocMemory(length + 1, sizeof(OFChar16)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, @@ -204,11 +204,11 @@ [self of_wideEnvironmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { - free(argumentsCopy); + OFFreeMemory(argumentsCopy); } } else { OFStringEncoding encoding = [OFLocale encoding]; STARTUPINFO si; Index: src/runtime/arc.m ================================================================== --- src/runtime/arc.m +++ src/runtime/arc.m @@ -20,11 +20,11 @@ #ifdef OF_HAVE_THREADS # import "mutex.h" #endif -struct weak_ref { +struct weakref { id **locations; size_t count; }; static struct objc_hashtable *hashtable; @@ -115,11 +115,11 @@ } id objc_storeWeak(id *object, id value) { - struct weak_ref *old; + struct weakref *old; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif @@ -153,11 +153,11 @@ } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { - struct weak_ref *ref = objc_hashtable_get(hashtable, value); + struct weakref *ref = objc_hashtable_get(hashtable, value); if (ref == NULL) { if ((ref = calloc(1, sizeof(*ref))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); @@ -186,11 +186,11 @@ id objc_loadWeakRetained(id *object) { id value = nil; - struct weak_ref *ref; + struct weakref *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif @@ -237,11 +237,11 @@ } void objc_moveWeak(id *dest, id *src) { - struct weak_ref *ref; + struct weakref *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif @@ -266,11 +266,11 @@ } void objc_zero_weak_references(id value) { - struct weak_ref *ref; + struct weakref *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif Index: tests/OFDataTests.m ================================================================== --- tests/OFDataTests.m +++ tests/OFDataTests.m @@ -32,12 +32,12 @@ OFRange range; TEST(@"+[dataWithItemSize:]", (mutable = [OFMutableData dataWithItemSize: 4096])) - raw[0] = of_alloc(1, 4096); - raw[1] = of_alloc(1, 4096); + raw[0] = OFAllocMemory(1, 4096); + raw[1] = OFAllocMemory(1, 4096); memset(raw[0], 0xFF, 4096); memset(raw[1], 0x42, 4096); TEST(@"-[addItem:]", R([mutable addItem: raw[0]]) && R([mutable addItem: raw[1]])) @@ -216,11 +216,11 @@ EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, [mutable removeItemsInRange: OFRangeMake(mutable.count, 1)]) - free(raw[0]); - free(raw[1]); + OFFreeMemory(raw[0]); + OFFreeMemory(raw[1]); objc_autoreleasePoolPop(pool); } @end Index: tests/OFStreamTests.m ================================================================== --- tests/OFStreamTests.m +++ tests/OFStreamTests.m @@ -66,18 +66,18 @@ size_t pageSize = [OFSystemInfo pageSize]; StreamTester *t = [[[StreamTester alloc] init] autorelease]; OFString *str; char *cstr; - cstr = of_alloc(pageSize - 2, 1); + cstr = OFAllocMemory(pageSize - 2, 1); memset(cstr, 'X', pageSize - 3); cstr[pageSize - 3] = '\0'; TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] && [(str = [t readLine]) length] == pageSize - 3 && !strcmp(str.UTF8String, cstr)) - free(cstr); + OFFreeMemory(cstr); objc_autoreleasePoolPop(pool); } @end Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -301,11 +301,11 @@ forKey: @"User-Agent"]; _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; - _buffer = of_alloc(1, [OFSystemInfo pageSize]); + _buffer = OFAllocMemory(1, [OFSystemInfo pageSize]); } @catch (id e) { [self release]; @throw e; }