[PR #1152] [MERGED] Fix dispose methods to always set _isDisposed and call base.Dispose() when LeaveOpen is true #1587

Open
opened 2026-01-29 22:21:15 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1152
Author: @Copilot
Created: 1/22/2026
Status: Merged
Merged: 1/22/2026
Merged by: @adamhathcock

Base: adam/async-creationHead: copilot/sub-pr-1132


📝 Commits (3)

  • b4f949b Initial plan
  • 336a8f2 Fix SharpCompressStream Dispose methods to set _isDisposed and call base.Dispose even when LeaveOpen is true
  • d9be638 Address code review feedback - remove extra blank lines and use consistent property access

📊 Changes

2 files changed (+10 additions, -3 deletions)

View changed files

📝 src/SharpCompress/IO/SharpCompressStream.Async.cs (+5 -2)
📝 src/SharpCompress/IO/SharpCompressStream.cs (+5 -1)

📄 Description

The dispose logic in SharpCompressStream returned early when LeaveOpen was true without setting _isDisposed or calling base.Dispose(), allowing subsequent dispose calls to re-execute disposal code.

Changes:

  • Restructured Dispose() and DisposeAsync() to always set _isDisposed and call base disposal methods
  • LeaveOpen check now only guards wrapped stream disposal and buffer cleanup
  • Verified no other dispose methods in codebase have this pattern

Before:

protected override void Dispose(bool disposing)
{
    if (_isDisposed || this.LeaveOpen)
    {
        return;  // Never sets _isDisposed or calls base.Dispose() when LeaveOpen=true
    }
    _isDisposed = true;
    base.Dispose(disposing);
    // ...
}

After:

protected override void Dispose(bool disposing)
{
    if (_isDisposed)
    {
        return;
    }
    _isDisposed = true;
    base.Dispose(disposing);
    if (this.LeaveOpen)
    {
        return;  // Skip only stream disposal and buffer cleanup
    }
    // ...
}

Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1152 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/22/2026 **Status:** ✅ Merged **Merged:** 1/22/2026 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `adam/async-creation` ← **Head:** `copilot/sub-pr-1132` --- ### 📝 Commits (3) - [`b4f949b`](https://github.com/adamhathcock/sharpcompress/commit/b4f949ba9be03a7143759d63178c616408f9c17b) Initial plan - [`336a8f2`](https://github.com/adamhathcock/sharpcompress/commit/336a8f2876583db0329da5ef19d7260a5723c92f) Fix SharpCompressStream Dispose methods to set _isDisposed and call base.Dispose even when LeaveOpen is true - [`d9be638`](https://github.com/adamhathcock/sharpcompress/commit/d9be6389cafd83afa1dd2c7d4a7484098926691e) Address code review feedback - remove extra blank lines and use consistent property access ### 📊 Changes **2 files changed** (+10 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/IO/SharpCompressStream.Async.cs` (+5 -2) 📝 `src/SharpCompress/IO/SharpCompressStream.cs` (+5 -1) </details> ### 📄 Description The dispose logic in `SharpCompressStream` returned early when `LeaveOpen` was true without setting `_isDisposed` or calling `base.Dispose()`, allowing subsequent dispose calls to re-execute disposal code. **Changes:** - Restructured `Dispose()` and `DisposeAsync()` to always set `_isDisposed` and call base disposal methods - `LeaveOpen` check now only guards wrapped stream disposal and buffer cleanup - Verified no other dispose methods in codebase have this pattern **Before:** ```csharp protected override void Dispose(bool disposing) { if (_isDisposed || this.LeaveOpen) { return; // Never sets _isDisposed or calls base.Dispose() when LeaveOpen=true } _isDisposed = true; base.Dispose(disposing); // ... } ``` **After:** ```csharp protected override void Dispose(bool disposing) { if (_isDisposed) { return; } _isDisposed = true; base.Dispose(disposing); if (this.LeaveOpen) { return; // Skip only stream disposal and buffer cleanup } // ... } ``` <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/adamhathcock/sharpcompress/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:21:15 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1587