diff options
author | 2024-08-02 14:11:24 +0000 | |
---|---|---|
committer | 2024-08-02 15:11:24 +0100 | |
commit | e5e996b28a31612f95961572c20cbd611e6211f9 (patch) | |
tree | a2f1fa05df77521e29d4efb97d59cd0de6f35384 /internal/media/util.go | |
parent | [chore] move PopulateAccountStats() nil check often performed into function i... (diff) | |
download | gotosocial-e5e996b28a31612f95961572c20cbd611e6211f9.tar.xz |
[bugfix] close files before error return (#3163)
* close files before error return
* use defer statements
* shuffle around some defers
Diffstat (limited to 'internal/media/util.go')
-rw-r--r-- | internal/media/util.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/internal/media/util.go b/internal/media/util.go index fa5c2bfd6..fa170965f 100644 --- a/internal/media/util.go +++ b/internal/media/util.go @@ -120,15 +120,17 @@ func getMimeType(ext string) string { // chance that Linux's sendfile syscall can be utilised for optimal // draining of data source to temporary file storage. func drainToTmp(rc io.ReadCloser) (string, error) { - tmp, err := os.CreateTemp(os.TempDir(), "gotosocial-*") + defer rc.Close() + + // Open new temporary file. + tmp, err := os.CreateTemp( + os.TempDir(), + "gotosocial-*", + ) if err != nil { return "", err } - - // Close readers - // on func return. defer tmp.Close() - defer rc.Close() // Extract file path. path := tmp.Name() |