ObjFW  Diff

Differences From Artifact [89d633e369]:

To Artifact [3cf4fd3893]:

  • File src/OFInflateStream.m — part of check-in [3b43d51006] at 2020-01-14 00:16:04 on branch trunk — More consistent -[close] behavior

    This means refusing to close twice, calling -[close] from -[dealloc] and
    not calling -[cancelAsyncRequests].

    Calling -[cancelAsyncRequests] in -[close] is too dangerous, as -[close]
    gets called by -[dealloc]: If the queue is the last reference to the
    object, at the point where -[cancelAsyncRequests] removes it from the
    queue, the object will start to deallocate and call into
    -[cancelAsyncRequests] again, which is still in the middle of removing
    it and now finds itself with an inconsistent state. (user: js, size: 16890) [annotate] [blame] [check-ins using] [more...]


204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
	}

	return self;
}

- (void)dealloc
{

	[self close];

	if (_state == HUFFMAN_TREE)
		if (_context.huffmanTree.codeLenTree != NULL)
			of_huffman_tree_release(
			    _context.huffmanTree.codeLenTree);

	if (_state == HUFFMAN_TREE || _state == HUFFMAN_BLOCK) {







>
|







204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	}

	return self;
}

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	if (_state == HUFFMAN_TREE)
		if (_context.huffmanTree.codeLenTree != NULL)
			of_huffman_tree_release(
			    _context.huffmanTree.codeLenTree);

	if (_state == HUFFMAN_TREE || _state == HUFFMAN_BLOCK) {
675
676
677
678
679
680
681



682
683
684
685
686
687
688
689
690
691
692
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _bufferLength - _bufferIndex > 0);
}

- (void)close
{



	/* Give back our buffer to the stream, in case it's shared */
	[_stream unreadFromBuffer: _buffer + _bufferIndex
			   length: _bufferLength - _bufferIndex];
	_bufferIndex = _bufferLength = 0;

	[_stream release];
	_stream = nil;

	[super close];
}
@end







>
>
>











676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
{
	return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer ||
	    _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;

	[_stream release];
	_stream = nil;

	[super close];
}
@end