@@ -150,21 +150,28 @@ public static void PutBackInPool(PooledBitReader reader)
150
150
/// </summary>
151
151
public sealed class PooledBitStream : BitStream , IDisposable
152
152
{
153
+ private bool isDisposed = false ;
153
154
/// <summary>
154
155
/// Gets a PooledBitStream from the static BitStreamPool
155
156
/// </summary>
156
157
/// <returns>PooledBitStream</returns>
157
158
public static PooledBitStream Get ( )
158
159
{
159
- return BitStreamPool . GetStream ( ) ;
160
+ PooledBitStream stream = BitStreamPool . GetStream ( ) ;
161
+ stream . isDisposed = false ;
162
+ return stream ;
160
163
}
161
164
162
165
/// <summary>
163
166
/// Returns the PooledBitStream into the static BitStreamPool
164
167
/// </summary>
165
168
public new void Dispose ( )
166
169
{
167
- BitStreamPool . PutBackInPool ( this ) ;
170
+ if ( ! isDisposed )
171
+ {
172
+ isDisposed = true ;
173
+ BitStreamPool . PutBackInPool ( this ) ;
174
+ }
168
175
}
169
176
}
170
177
@@ -173,6 +180,8 @@ public static PooledBitStream Get()
173
180
/// </summary>
174
181
public sealed class PooledBitWriter : BitWriter , IDisposable
175
182
{
183
+ private bool isDisposed = false ;
184
+
176
185
public PooledBitWriter ( Stream stream ) : base ( stream )
177
186
{
178
187
@@ -184,15 +193,21 @@ public PooledBitWriter(Stream stream) : base(stream)
184
193
/// <returns>PooledBitWriter</returns>
185
194
public static PooledBitWriter Get ( Stream stream )
186
195
{
187
- return BitWriterPool . GetWriter ( stream ) ;
196
+ PooledBitWriter writer = BitWriterPool . GetWriter ( stream ) ;
197
+ writer . isDisposed = false ;
198
+ return writer ;
188
199
}
189
200
190
201
/// <summary>
191
202
/// Returns the PooledBitWriter into the static BitWriterPool
192
203
/// </summary>
193
204
public void Dispose ( )
194
205
{
195
- BitWriterPool . PutBackInPool ( this ) ;
206
+ if ( ! isDisposed )
207
+ {
208
+ isDisposed = true ;
209
+ BitWriterPool . PutBackInPool ( this ) ;
210
+ }
196
211
}
197
212
}
198
213
@@ -201,6 +216,8 @@ public void Dispose()
201
216
/// </summary>
202
217
public sealed class PooledBitReader : BitReader , IDisposable
203
218
{
219
+ private bool isDisposed = false ;
220
+
204
221
public PooledBitReader ( Stream stream ) : base ( stream )
205
222
{
206
223
}
@@ -211,15 +228,21 @@ public PooledBitReader(Stream stream) : base(stream)
211
228
/// <returns>PooledBitReader</returns>
212
229
public static PooledBitReader Get ( Stream stream )
213
230
{
214
- return BitReaderPool . GetReader ( stream ) ;
231
+ PooledBitReader reader = BitReaderPool . GetReader ( stream ) ;
232
+ reader . isDisposed = false ;
233
+ return reader ;
215
234
}
216
235
217
236
/// <summary>
218
237
/// Returns the PooledBitReader into the static BitReaderPool
219
238
/// </summary>
220
239
public void Dispose ( )
221
240
{
222
- BitReaderPool . PutBackInPool ( this ) ;
241
+ if ( ! isDisposed )
242
+ {
243
+ isDisposed = true ;
244
+ BitReaderPool . PutBackInPool ( this ) ;
245
+ }
223
246
}
224
247
}
225
248
}
0 commit comments