@@ -82,18 +82,16 @@ - (OFString *)stringByURLDecoding { void *pool = objc_autoreleasePoolPush(); const char *string = self.UTF8String; size_t length = self.UTF8StringLength; - char *retCString, *retCString2; + char *retCString; char byte = 0; int state = 0; size_t i = 0; - if ((retCString = malloc(length + 1)) == NULL) - @throw [OFOutOfMemoryException - exceptionWithRequestedSize: length + 1]; + retCString = of_malloc(1, length + 1); while (length--) { char c = *string++; switch (state) { @@ -112,11 +110,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); + of_free(retCString); @throw [OFInvalidFormatException exception]; } if (++state == 3) { retCString[i++] = byte; @@ -130,18 +128,20 @@ retCString[i] = '\0'; objc_autoreleasePoolPop(pool); if (state != 0) { - free(retCString); + of_free(retCString); @throw [OFInvalidFormatException exception]; } - /* We don't care if it fails, as we only made it smaller. */ - if ((retCString2 = realloc(retCString, i + 1)) == NULL) - retCString2 = retCString; + @try { + retCString = of_realloc(retCString, 1, i + 1); + } @catch (OFOutOfMemoryException *e) { + /* We don't care if it fails, as we only made it smaller. */ + } - return [OFString stringWithUTF8StringNoCopy: retCString2 + return [OFString stringWithUTF8StringNoCopy: retCString length: i freeWhenDone: true]; } @end