@@ -206,11 +206,12 @@ return self; } - (void)dealloc { - [self close]; + if (_stream != nil) + [self close]; if (_state == HUFFMAN_TREE) if (_context.huffmanTree.codeLenTree != NULL) of_huffman_tree_release( _context.huffmanTree.codeLenTree); @@ -677,10 +678,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]; _bufferIndex = _bufferLength = 0;