Fix image memory issue (#935)

* Return slim images from mutations
* Fix potential memory leaks
This commit is contained in:
WithoutPants
2020-11-10 20:19:13 +11:00
committed by GitHub
parent ceb888958e
commit beb84b8e94
3 changed files with 9 additions and 3 deletions

View File

@@ -16,7 +16,7 @@ mutation ImageUpdate(
performer_ids: $performer_ids,
tag_ids: $tag_ids
}) {
...ImageData
...SlimImageData
}
}
@@ -38,13 +38,13 @@ mutation BulkImageUpdate(
performer_ids: $performer_ids,
tag_ids: $tag_ids
}) {
...ImageData
...SlimImageData
}
}
mutation ImagesUpdate($input : [ImageUpdateInput!]!) {
imagesUpdate(input: $input) {
...ImageData
...SlimImageData
}
}

View File

@@ -90,11 +90,15 @@ func openSourceImage(path string) (io.ReadCloser, error) {
return nil, err
}
// defer closing of zip to the calling function, unless an error
// is returned, in which case it should be closed immediately
// find the file matching the filename
for _, f := range r.File {
if f.Name == filename {
src, err := f.Open()
if err != nil {
r.Close()
return nil, err
}
return &imageReadCloser{
@@ -104,6 +108,7 @@ func openSourceImage(path string) (io.ReadCloser, error) {
}
}
r.Close()
return nil, fmt.Errorf("file with name '%s' not found in zip file '%s'", filename, zipFilename)
}

View File

@@ -67,6 +67,7 @@ func walkGalleryZip(path string, walkFunc func(file *zip.File) error) error {
if err != nil {
return err
}
defer readCloser.Close()
for _, file := range readCloser.File {
if file.FileInfo().IsDir() {