From 9760b4e977494c492b8b8810742f79b92f643399 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 11 Jan 2018 17:58:09 +0000
Subject: [PATCH] Close the file if we open it. It's not enough for the file to
 go out of scope. :-( This fixes the download problem (on Windows at least) in
 avatar_chooser.js

---
 exec/load/sauce_lib.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/exec/load/sauce_lib.js b/exec/load/sauce_lib.js
index b01115d8f1..c9c6b8d037 100644
--- a/exec/load/sauce_lib.js
+++ b/exec/load/sauce_lib.js
@@ -60,12 +60,18 @@ function read(fname)
 			return false;
 	}
 
-	if(file.length < defs.trailer_length)
+	if(file.length < defs.trailer_length) {
+		if(typeof fname != 'object')
+			file.close();
 		return false;
+	}
 
 	file.position = file.length - defs.trailer_length;
-	if(file.read(defs.id_length + defs.version_length) != 'SAUCE00')
+	if(file.read(defs.id_length + defs.version_length) != 'SAUCE00') {
+		if(typeof fname != 'object')
+			file.close();
 		return false;
+	}
 
 	var obj = {};
 	obj.title = truncsp(file.read(35));
@@ -119,6 +125,8 @@ function read(fname)
 			}
 		}
 	}
+	if(typeof fname != 'object')
+		file.close();
 	return obj;
 }
 
@@ -177,6 +185,8 @@ function write(fname, obj)
 	file.writeBin(obj.comment.length, 1);
 	file.writeBin(obj.tflags, 1);
 	file.write(valueof(obj.tinfos), 22);
+	if(typeof fname != 'object')
+		file.close();
 	return true;
 }
 
@@ -194,7 +204,10 @@ function remove(fname)
 	}
 
 	var obj = this.read(file);
-	return file.truncate(obj.filesize);
+	var result = file.truncate(obj.filesize);
+	if(typeof fname != 'object')
+		file.close();
+	return result;
 }
 
 this;
-- 
GitLab