@@ -121,11 +121,12 @@ return self; } - (void)dealloc { - [self close]; + if (_stream != nil) + [self close]; if (_codeLenTree != NULL) of_huffman_tree_release(_codeLenTree); if (_litLenTree != NULL) of_huffman_tree_release(_litLenTree); @@ -514,10 +515,13 @@ _bufferLength - _bufferIndex > 0); } - (void)close { + if (_stream == nil) + @throw [OFNotOpenException exceptionWithObject: self]; + /* Give back our buffer to the stream, in case it's shared */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bytesConsumed -= _bufferLength - _bufferIndex; _bufferIndex = _bufferLength = 0;