Skip to content

Commit 6bb039d

Browse files
committed
cli/config/configfile: Make sure to not leak a temp config behind.
In the unlikely event that we fail to rename the temp config file to the destination file, don't leave the temp config file behind as this could cause temp files to pile up in ~/.docker for example if there is a permission problem. Signed-off-by: Benoit Sigoure <tsunanet@gmail.com>
1 parent 82dff32 commit 6bb039d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

cli/config/configfile/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ func (configFile *ConfigFile) Save() error {
183183
if err != nil {
184184
return err
185185
}
186+
defer os.Remove(temp.Name())
186187
err = configFile.SaveToWriter(temp)
187188
temp.Close()
188189
if err != nil {
189-
os.Remove(temp.Name())
190190
return err
191191
}
192192
return os.Rename(temp.Name(), configFile.Filename)

0 commit comments

Comments
 (0)