Permalink
Browse files

Fixed a global variable leak

  • Loading branch information...
1 parent e9d74da commit 56dbbb3819ef2ada1b01f3044007371d790af58d @patrickod patrickod committed Dec 4, 2012
Showing with 13 additions and 13 deletions.
  1. +13 −13 lib/memcache.js
View
26 lib/memcache.js
@@ -25,7 +25,7 @@
var tcp = require('net'),
util = require('util');
-
+
var crlf = "\r\n";
var crlf_len = crlf.length;
@@ -53,22 +53,22 @@ Client.prototype.connect = function () {
this.setNoDelay();
self.emit("connect");
self.dispatchHandles();
- });
-
+ });
+
this.conn.addListener("data", function (data) {
self.buffer += data;
// util.debug(data);
self.recieves += 1;
self.handle_received_data();
});
-
+
this.conn.addListener("end", function () {
if (self.conn && self.conn.readyState) {
self.conn.end();
self.conn = null;
}
});
-
+
this.conn.addListener("close", function () {
self.conn = null;
self.emit("close");
@@ -88,7 +88,7 @@ Client.prototype.connect = function () {
Client.prototype.addHandler = function(callback) {
this.handles.push(callback);
-
+
if (this.conn.readyState == 'open') {
this.dispatchHandles();
}
@@ -163,7 +163,7 @@ Client.prototype.cas = function(key, value, unique, callback, lifetime, flags) {
Client.prototype.del = function(key, callback){
util.error("mc.del() is deprecated - use mc.delete() instead");
- return this.delete(key, callback);
+ return this.delete(key, callback);
};
Client.prototype.delete = function(key, callback){
@@ -211,7 +211,7 @@ Client.prototype.stats = function(type, callback){
}
Client.prototype.handle_received_data = function(){
-
+
while (this.buffer.length > 0){
var result = this.determine_reply_handler(this.buffer);
@@ -247,7 +247,7 @@ Client.prototype.determine_reply_handler = function (buffer){
if (crlf_at == -1){
return null;
}
-
+
// determine errors
for (var error_idx in error_replies){
var error_indicator = error_replies[error_idx];
@@ -270,20 +270,20 @@ Client.prototype.handle_get = function(buffer) {
var result_value = null;
var end_indicator_len = 3;
var result_len = 0;
-
+
if (buffer.indexOf('END') == 0) {
return [result_value, end_indicator_len + crlf_len];
} else if (buffer.indexOf('VALUE') == 0 && buffer.indexOf('END') != -1) {
first_line_len = buffer.indexOf(crlf) + crlf_len;
var end_indicator_start = buffer.indexOf('END');
result_len = end_indicator_start - first_line_len - crlf_len;
result_value = buffer.substr(first_line_len, result_len);
- return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len]
+ return [result_value, first_line_len + parseInt(result_len, 10) + crlf_len + end_indicator_len + crlf_len]
} else {
var first_line_len = buffer.indexOf(crlf) + crlf_len;
var result_len = buffer.substr(0, first_line_len).split(' ')[3];
result_value = buffer.substr(first_line_len, result_len);
-
+
return [result_value, first_line_len + parseInt(result_len ) + crlf_len + end_indicator_len + crlf_len];
}
};
@@ -333,7 +333,7 @@ Client.prototype.handle_version = function(buffer){
};
Client.prototype.handle_error = function(buffer){
- line = readLine(buffer);
+ var line = readLine(buffer);
return [null, (line.length + crlf_len), line];
};

0 comments on commit 56dbbb3

Please sign in to comment.