-
-
Save indutny/299ad3f2825816f2b6f7 to your computer and use it in GitHub Desktop.
1.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 0972acb5481065d79eaca1f1fc6e009fea70b144 | |
Author: Fedor Indutny <fedor.indutny@gmail.com> | |
Date: Sun Jan 27 19:25:54 2013 +0400 | |
stream_wrap: reference handle before uv_write2 | |
Revert commit 7f2a78bf4d494806ccabcccdeb8579dcc4405a8d and fix using | |
empty symbol handle. | |
diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc | |
index 1df8734..910e94b 100644 | |
--- a/src/stream_wrap.cc | |
+++ b/src/stream_wrap.cc | |
@@ -77,6 +77,7 @@ static Persistent<String> bytes_sym; | |
static Persistent<String> write_queue_size_sym; | |
static Persistent<String> onread_sym; | |
static Persistent<String> oncomplete_sym; | |
+static Persistent<String> handle_sym; | |
static SlabAllocator* slab_allocator; | |
static bool initialized; | |
@@ -411,6 +412,14 @@ Handle<Value> StreamWrap::WriteStringImpl(const Arguments& args) { | |
StreamWrap* send_stream_wrap = static_cast<StreamWrap*>( | |
send_stream_obj->GetAlignedPointerFromInternalField(0)); | |
send_stream = send_stream_wrap->GetStream(); | |
+ | |
+ // Reference StreamWrap instance to prevent it from being garbage | |
+ // collected before `AfterWrite` is called. | |
+ if (handle_sym.IsEmpty()) { | |
+ handle_sym = NODE_PSYMBOL("handle"); | |
+ } | |
+ assert(!req_wrap->object_.IsEmpty()); | |
+ req_wrap->object_->Set(handle_sym, send_stream_obj); | |
} | |
r = uv_write2(&req_wrap->req_, | |
@@ -468,6 +477,11 @@ void StreamWrap::AfterWrite(uv_write_t* req, int status) { | |
assert(req_wrap->object_.IsEmpty() == false); | |
assert(wrap->object_.IsEmpty() == false); | |
+ // Unref handle property | |
+ if (!handle_sym.IsEmpty()) { | |
+ req_wrap->object_->Delete(handle_sym); | |
+ } | |
+ | |
if (status) { | |
SetErrno(uv_last_error(uv_default_loop())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment