Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -123,12 +123,11 @@ @implementation OFMutableString - setToCString: (const char*)str { size_t len; - if (string != NULL) - [self freeMemory: string]; + [self freeMemory: string]; len = strlen(str); switch (of_string_check_utf8(str, len)) { case 0: Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -246,10 +246,11 @@ toNItems: (size_t)nitems withSize: (size_t)size; /** * Frees allocated memory and removes it from the object's memory pool. + * Does nothing if ptr is NULL. * * \param ptr A pointer to the allocated memory */ - freeMemory: (void*)ptr; Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -389,10 +389,13 @@ - freeMemory: (void*)ptr; { void **iter, *last, **memchunks; size_t i, memchunks_size; + + if (ptr == NULL) + return self; iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size; i = PRE_IVAR->memchunks_size; while (iter-- > PRE_IVAR->memchunks) { Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -150,17 +150,15 @@ [self freeMemory: tmp]; @throw e; } memcpy(tmp2, tmp + i + 1, len - i - 1); - if (cache != NULL) - [self freeMemory: cache]; + [self freeMemory: cache]; cache = tmp2; cache_len = len - i - 1; } else { - if (cache != NULL) - [self freeMemory: cache]; + [self freeMemory: cache]; cache = NULL; cache_len = 0; } [self freeMemory: tmp]; @@ -217,12 +215,11 @@ return cache_len; } - clearCache { - if (cache != NULL) - [self freeMemory: cache]; + [self freeMemory: cache]; cache = NULL; cache_len = 0; return self; Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -312,14 +312,13 @@ - close { if (sock == INVALID_SOCKET) @throw [OFNotConnectedException newWithClass: isa]; + [self freeMemory: saddr]; sock = INVALID_SOCKET; - - if (saddr != NULL) - [self freeMemory: saddr]; + saddr = NULL; saddr_len = 0; return self; } @end