mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] close files before error return (#3163)
* close files before error return * use defer statements * shuffle around some defers
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user