Skip to content

Commit 5329e5e

Browse files
committed
check if the uv_poll_t struct is initialized before calling uv_poll_stop
Before this fix a call to End after an error in Connect() would result in a segfault. brianc#136 (comment)
1 parent 3680b59 commit 5329e5e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/binding.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,14 @@ class Connection : public ObjectWrap {
234234

235235
uv_poll_t read_watcher_;
236236
uv_poll_t write_watcher_;
237-
238237
PGconn *connection_;
239238
bool connecting_;
239+
bool ioInitialized_;
240240
Connection () : ObjectWrap ()
241241
{
242242
connection_ = NULL;
243243
connecting_ = false;
244+
ioInitialized_ = false;
244245

245246
TRACE("Initializing ev watchers");
246247
read_watcher_.data = this;
@@ -354,6 +355,8 @@ class Connection : public ObjectWrap {
354355
uv_poll_init(uv_default_loop(), &read_watcher_, fd);
355356
uv_poll_init(uv_default_loop(), &write_watcher_, fd);
356357

358+
ioInitialized_ = true;
359+
357360
connecting_ = true;
358361
StartWrite();
359362

@@ -616,7 +619,9 @@ class Connection : public ObjectWrap {
616619
void StopWrite()
617620
{
618621
TRACE("Stoping write watcher");
619-
uv_poll_stop(&write_watcher_);
622+
if(ioInitialized_) {
623+
uv_poll_stop(&write_watcher_);
624+
}
620625
}
621626

622627
void StartWrite()
@@ -628,7 +633,9 @@ class Connection : public ObjectWrap {
628633
void StopRead()
629634
{
630635
TRACE("Stoping read watcher");
631-
uv_poll_stop(&read_watcher_);
636+
if(ioInitialized_) {
637+
uv_poll_stop(&read_watcher_);
638+
}
632639
}
633640

634641
void StartRead()

0 commit comments

Comments
 (0)