@@ -180,44 +180,49 @@ } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { + char *buffer = NULL; + uintmax_t size; + @try { - uintmax_t size = [[[OFFileManager defaultManager] + OFFile *file; + + size = [[[OFFileManager defaultManager] attributesOfItemAtPath: path] fileSize]; - char *buffer; # if UINTMAX_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif - buffer = malloc((size_t)size); - if (buffer == NULL) + if ((buffer = malloc((size_t)size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: (size_t)size]; - @try { - OFFile *file = [[OFFile alloc] initWithPath: path - mode: @"r"]; - @try { - [file readIntoBuffer: buffer - exactLength: (size_t)size]; - } @finally { - [file release]; - } - - self = [self initWithItemsNoCopy: buffer - count: (size_t)size - freeWhenDone: true]; - } @catch (id e) { - free(buffer); - @throw e; - } - } @catch (id e) { - [self release]; + file = [[OFFile alloc] initWithPath: path + mode: @"r"]; + @try { + [file readIntoBuffer: buffer + exactLength: (size_t)size]; + } @finally { + [file release]; + } + } @catch (id e) { + free(buffer); + [self release]; + + @throw e; + } + + @try { + self = [self initWithItemsNoCopy: buffer + count: (size_t)size + freeWhenDone: true]; + } @catch (id e) { + free(buffer); @throw e; } return self; } @@ -351,27 +356,27 @@ return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { + void *pool = objc_autoreleasePoolPush(); + OFString *stringValue; + @try { - void *pool = objc_autoreleasePoolPush(); - OFString *stringValue; - if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exception]; stringValue = [element stringValue]; - - self = [self initWithBase64EncodedString: stringValue]; - - objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } + + self = [self initWithBase64EncodedString: stringValue]; + + objc_autoreleasePoolPop(pool); return self; } - (void)dealloc