Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Add HandleScope to http-parser binding
Browse files Browse the repository at this point in the history
Fixes production crashes. We were not able to reproduce in the test suite.
  • Loading branch information
ry committed Dec 21, 2011
1 parent 07c27e0 commit 73cf8e8
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ static size_t current_buffer_len;


#define HTTP_CB(name) \
static int name(http_parser* p_) { \
Parser* self = container_of(p_, Parser, parser_); \
return self->name##_(); \
} \
int always_inline name##_()
static int name(http_parser* p_) { \
HandleScope scope; \
Parser* self = container_of(p_, Parser, parser_); \
return self->name##_(); \
} \
int always_inline name##_()


#define HTTP_DATA_CB(name) \
static int name(http_parser* p_, const char* at, size_t length) { \
HandleScope scope; \
Parser* self = container_of(p_, Parser, parser_); \
return self->name##_(at, length); \
} \
Expand Down Expand Up @@ -212,10 +214,12 @@ struct StringPtr {


Handle<String> ToString() const {
if (str_)
return String::New(str_, size_);
else
return String::Empty();
HandleScope scope;
if (str_) {
return scope.Close(String::New(str_, size_));
} else {
return scope.Close(String::Empty());
}
}


Expand Down Expand Up @@ -513,6 +517,8 @@ class Parser : public ObjectWrap {
private:

Local<Array> CreateHeaders() {
HandleScope scope;

// num_values_ is either -1 or the entry # of the last header
// so num_values_ == 0 means there's a single header
Local<Array> headers = Array::New(2 * (num_values_ + 1));
Expand All @@ -522,7 +528,7 @@ class Parser : public ObjectWrap {
headers->Set(2 * i + 1, values_[i].ToString());
}

return headers;
return scope.Close(headers);
}


Expand Down

0 comments on commit 73cf8e8

Please sign in to comment.