@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in @@ -82,10 +82,11 @@ size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; size_t i = 0; + OFString *ret; retCString = OFAllocMemory(length + 1, 1); while (length--) { char c = *string++; @@ -135,14 +136,16 @@ } @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]; + ret = [OFString stringWithUTF8StringNoCopy: retCString + length: i + freeWhenDone: true]; } @catch (id e) { OFFreeMemory(retCString); @throw e; } + + return ret; } @end