Skip to content

This is _not_ a good Dispose() call :) #2337

Open
@the-exodus

Description

@the-exodus

This is not really a huge issue, but the provided example in csharp/ql/src/API Abuse/MissingDisposeCallGood.cs is actually quite bad, as it can lead to all kinds of pointer-related issues (anything from a mysterious crashes to arbitrary code execution).

As you're a security-focused code analysis service, I really think a proper implementation of the Disposable-pattern would be in order :)

class MyClass : IDisposable
{
   bool disposed = false;

   public void Dispose()
   { 
      Dispose(true);
      GC.SuppressFinalize(this);           
   }

   protected virtual void Dispose(bool disposing)
   {
      if (disposed)
         return; 
      
      if (disposing) {
    // free any managed objects
      }
      
      // Free any unmanaged objects
      disposed = true;
   }

   ~MyClass()
   {
      Dispose(false);
   }
} 

Metadata

Metadata

Assignees

Labels

C#questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions