@@ -28,14 +28,11 @@ static struct of_huffman_tree * newTree(void) { struct of_huffman_tree *tree; - if ((tree = malloc(sizeof(*tree))) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: sizeof(*tree)]; - + tree = of_malloc(1, sizeof(*tree)); tree->leaves[0] = tree->leaves[1] = NULL; tree->value = 0xFFFF; return tree; } @@ -70,24 +67,14 @@ @try { for (uint16_t i = 0; i < count; i++) { uint_fast8_t length = lengths[i]; if OF_UNLIKELY (length > maxBit) { - size_t size = (length + 1) * sizeof(uint16_t); - uint16_t *new; - - if ((new = realloc(lengthCount, size)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: size]; - - lengthCount = new; - - if ((new = realloc(nextCode, size)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: size]; - - nextCode = new; + lengthCount = of_realloc(lengthCount, + length + 1, sizeof(uint16_t)); + nextCode = of_realloc(nextCode, + length + 1, sizeof(uint16_t)); for (uint_fast8_t j = maxBit + 1; j <= length; j++) { lengthCount[j] = 0; nextCode[j] = 0; @@ -115,12 +102,12 @@ if (length > 0) insertTree(tree, nextCode[length]++, length, i); } } @finally { - free(lengthCount); - free(nextCode); + of_free(lengthCount); + of_free(nextCode); } return tree; } @@ -139,7 +126,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); + of_free(tree); }