Skip to content

Commit

Permalink
Avoid calling Unref on a closed port
Browse files Browse the repository at this point in the history
  • Loading branch information
drewish committed Apr 6, 2014
1 parent 78548c3 commit 12ccdd2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node-midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,14 @@ class NodeMidiInput : public ObjectWrap
input->in->openVirtualPort(name);
return scope.Close(v8::Undefined());
}

static v8::Handle<v8::Value> ClosePort(const v8::Arguments& args)
{
v8::HandleScope scope;
NodeMidiInput* input = ObjectWrap::Unwrap<NodeMidiInput>(args.This());
input->Unref();
if (input->in->isPortOpen()) {
input->Unref();
}
input->in->closePort();
uv_close((uv_handle_t*)&input->message_async, NULL);
return scope.Close(v8::Undefined());
Expand Down
16 changes: 16 additions & 0 deletions test/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe('midi.input', function() {
input.getPortName(999).should.eql('');
});
});

describe('.closePort', function() {
var input = new Midi.input();

it('allows you to close a port that was not opened', function() {
input.closePort();
});
});
});

describe('midi.output', function() {
Expand Down Expand Up @@ -82,4 +90,12 @@ describe('midi.output', function() {
output.getPortName(999).should.eql('');
});
});

describe('.closePort', function() {
var output = new Midi.output();

it('allows you to close a port that was not opened', function() {
output.closePort();
});
});
});

0 comments on commit 12ccdd2

Please sign in to comment.