Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -68,11 +68,11 @@ return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString*)readLineWithEncoding: (enum of_string_encoding)encoding { - size_t i, len; + size_t i, len, ret_len; char *ret_c, *tmp, *tmp2; OFString *ret; /* Look if there's a line or \0 in our cache */ if (cache != NULL) { @@ -126,13 +126,14 @@ } /* Look if there's a newline or \0 */ for (i = 0; i < len; i++) { if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) { + ret_len = cache_len + i; @try { ret_c = [self - allocMemoryWithSize: cache_len + i]; + allocMemoryWithSize: ret_len]; } @catch (OFException *e) { [self freeMemory: tmp]; @throw e; } if (cache != NULL) @@ -165,11 +166,11 @@ @try { ret = [OFString stringWithCString: ret_c encoding: encoding - length: cache_len + i]; + length: ret_len]; } @finally { [self freeMemory: ret_c]; } return ret; }