Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -37,11 +37,11 @@ #ifdef OF_FILE_HANDLE_IS_FD #endif { OFFileHandle _handle; - bool _atEndOfStream; + bool _initialized, _atEndOfStream; } /** * @brief Creates a new OFFile with the specified path and mode. * Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -339,10 +339,11 @@ - (instancetype)initWithHandle: (OFFileHandle)handle { self = [super init]; _handle = handle; + _initialized = true; return self; } - (instancetype)init @@ -554,11 +555,11 @@ [super close]; } - (void)dealloc { - if (_handle != OFInvalidFileHandle) + if (_initialized && _handle != OFInvalidFileHandle) [self close]; [super dealloc]; } @end