public
Created

  • Download Gist
0001-Potential-fix-for-2438.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
From 272ef4891ccdb23f267b984e0f47c0274961604d Mon Sep 17 00:00:00 2001
From: Ryan Dahl <ry@tinyclouds.org>
Date: Thu, 29 Dec 2011 16:06:14 -0800
Subject: [PATCH] Potential fix for #2438
 
---
src/node_http_parser.cc | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
 
diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index 38251a1..4df3ac3 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -179,6 +179,19 @@ struct StringPtr {
}
+ // If str_ does not point to a heap string yet, this function makes it do
+ // so. This is called at the end of each http_parser_execute() so as not
+ // to leak references. See issue #2438 and test-http-parser-bad-ref.js.
+ void Save() {
+ if (!on_heap_) {
+ char* s = new char[size_];
+ memcpy(s, str_, size_);
+ str_ = s;
+ on_heap_ = true;
+ }
+ }
+
+
void Reset() {
if (on_heap_) {
delete[] str_;
@@ -401,6 +414,19 @@ public:
}
+ void Save() {
+ url_.Save();
+
+ for (int i = 0; i < num_fields_; i++) {
+ fields_[i].Save();
+ }
+
+ for (int i = 0; i < num_values_; i++) {
+ values_[i].Save();
+ }
+ }
+
+
// var bytesParsed = parser->execute(buffer, off, len);
static Handle<Value> Execute(const Arguments& args) {
HandleScope scope;
@@ -447,6 +473,8 @@ public:
size_t nparsed =
http_parser_execute(&parser->parser_, &settings, buffer_data + off, len);
+ parser->Save();
+
// Unassign the 'buffer_' variable
assert(current_buffer);
current_buffer = NULL;
--
1.7.2

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.