From 55e964ec19e23467576466a5975f8fb91c176ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 3 Jun 2010 12:37:21 +0200 Subject: [PATCH] Fix: fs.readFile would execute callbacks twice fs.readFile was executing a callback in a try..catch context, which is a problem in itself. To make matters worse, it would re-execute the same callback if there was an execution. This patch fixes both of these problems. --- lib/fs.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/fs.js b/lib/fs.js index 8724e7039ad..3ab3f7240b7 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -73,10 +73,12 @@ fs.readFile = function (path, encoding_, callback) { binding.close(fd); if (encoding) { try { - callback(null, buffer.toString(encoding)); + var str = buffer.toString(encoding); } catch (err) { callback(err); + return; } + callback(null, str); } else { callback(null, buffer); }