Cleanup potential memory leaks
Some checks failed
Build and Push Image / build-and-push (push) Has been cancelled
Some checks failed
Build and Push Image / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -79,6 +79,10 @@ public class AobaService(IMongoDatabase db)
|
|||||||
{
|
{
|
||||||
return ex;
|
return ex;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
data.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<MaybeEx<GridFSDownloadStream, GridFSException>> GetFileStreamAsync(ObjectId mediaId, bool seekable = false, CancellationToken cancellationToken = default)
|
public async Task<MaybeEx<GridFSDownloadStream, GridFSException>> GetFileStreamAsync(ObjectId mediaId, bool seekable = false, CancellationToken cancellationToken = default)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Maybe<Image> LoadImageAsync(Stream stream, string ext)
|
private static Maybe<Image> LoadImage(Stream stream, string ext)
|
||||||
{
|
{
|
||||||
if (ext is ".heif" or ".avif")
|
if (ext is ".heif" or ".avif")
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,7 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
|
|
||||||
public static async Task<Maybe<Stream>> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, string ext, CancellationToken cancellationToken = default)
|
public static async Task<Maybe<Stream>> GenerateImageThumbnailAsync(Stream stream, ThumbnailSize size, string ext, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var img = LoadImageAsync(stream, ext);
|
var img = LoadImage(stream, ext);
|
||||||
if (img.HasError)
|
if (img.HasError)
|
||||||
return img.Error;
|
return img.Error;
|
||||||
img.Value.Mutate(o =>
|
img.Value.Mutate(o =>
|
||||||
@@ -125,6 +125,7 @@ public class ThumbnailService(IMongoDatabase db, AobaService aobaService)
|
|||||||
Size = new Size(300, 300)
|
Size = new Size(300, 300)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
img.Value.Dispose();
|
||||||
var result = new MemoryStream();
|
var result = new MemoryStream();
|
||||||
await img.Value.SaveAsWebpAsync(result, cancellationToken);
|
await img.Value.SaveAsWebpAsync(result, cancellationToken);
|
||||||
result.Position = 0;
|
result.Position = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user