Problem
SKImage.FromEncodedData(SKData data, SKRectI subset) creates an intermediate SKImage from encoded data then calls .Subset() on it, but never disposes the intermediate. If Subset() returns a different instance, the intermediate leaks. If it returns the same instance (same-instance-return behavior), disposing the intermediate would destroy the result. The fix must handle both cases using the standard same-instance safety pattern.
Location
- File(s):
binding/SkiaSharp/SKImage.cs
- Line(s): 158–164
Current Code
public static SKImage FromEncodedData (SKData data, SKRectI subset)
{
if (data == null)
throw new ArgumentNullException (nameof (data));
return FromEncodedData (data)?.Subset (subset);
}
Suggested Fix
public static SKImage FromEncodedData (SKData data, SKRectI subset)
{
if (data == null)
throw new ArgumentNullException (nameof (data));
var image = FromEncodedData (data);
if (image == null)
return null;
var result = image.Subset (subset);
if (result != image)
image.Dispose ();
return result;
}
SkiaSharp Guidelines
Acceptance Criteria
Part of #3976
Generated by Nightly Fix Finder · ● 2.4M · ◷
Problem
SKImage.FromEncodedData(SKData data, SKRectI subset)creates an intermediateSKImagefrom encoded data then calls.Subset()on it, but never disposes the intermediate. IfSubset()returns a different instance, the intermediate leaks. If it returns the same instance (same-instance-return behavior), disposing the intermediate would destroy the result. The fix must handle both cases using the standard same-instance safety pattern.Location
binding/SkiaSharp/SKImage.csCurrent Code
Suggested Fix
SkiaSharp Guidelines
*.generated.csfile#ifguards unless they genuinely benefit all callersAcceptance Criteria
FromEncodedData(data)is disposed whenSubset()returns a different instanceSubset()returns the same instanceFromEncodedData(data)returns nulldotnet test tests/SkiaSharp.Tests.Console/SkiaSharp.Tests.Console.csprojPart of #3976