From d853941f9ee83c791a09014bec868f8c9bca4ccd Mon Sep 17 00:00:00 2001 From: Julien Pilet Date: Sat, 11 Apr 2015 19:04:41 +0200 Subject: [PATCH] Fix a memory leak in SerialportPoller::New If argument checking fails, the newly allocated SerialportPoller in SerialportPoller::New was not deleted. --- src/serialport_poller.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/serialport_poller.cpp b/src/serialport_poller.cpp index 4b5f213..51c9316 100644 --- a/src/serialport_poller.cpp +++ b/src/serialport_poller.cpp @@ -76,18 +76,18 @@ void SerialportPoller::Init(Handle target) { NAN_METHOD(SerialportPoller::New) { NanScope(); - SerialportPoller* obj = new SerialportPoller(); - if(!args[0]->IsInt32()) { NanThrowTypeError("First argument must be an fd"); NanReturnUndefined(); } - obj->fd_ = args[0]->ToInt32()->Int32Value(); if(!args[1]->IsFunction()) { NanThrowTypeError("Third argument must be a function"); NanReturnUndefined(); } + + SerialportPoller* obj = new SerialportPoller(); + obj->fd_ = args[0]->ToInt32()->Int32Value(); obj->callback_ = new NanCallback(args[1].As()); // obj->callCallback();