Skip to content

Commit c861c81

Browse files
author
John Haley
committed
Fix segfault in Branch.name
The generated C++ code was freeing the out parameter because it was a string even though the string was of type `const`. Now we have a safeguard in place so we aren't freeing things that we shouldn't be in this case.
1 parent f645360 commit c861c81

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

generate/templates/filters/args_info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = function(args) {
2222

2323
arg.cArg = cArg;
2424
arg.isCppClassStringOrArray = ~["String", "Array"].indexOf(arg.cppClassName);
25+
arg.isConst = ~arg.cType.indexOf("const ");
2526

2627
// if we have a callback then we also need the corresponding payload for that callback
2728
if (arg.isCallbackFunction) {

generate/templates/partials/async_function.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void {{ cppClassName }}::{{ cppFunctionName }}Worker::HandleOKCallback() {
250250
{%if arg.isCppClassStringOrArray %}
251251
{%if arg.freeFunctionName %}
252252
{{ arg.freeFunctionName }}(baton->{{ arg.name }});
253-
{%else%}
253+
{%elsif not arg.isConst%}
254254
free((void *)baton->{{ arg.name }});
255255
{%endif%}
256256
{%elsif arg | isOid %}

test/tests/branch.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ describe("Branch", function() {
6868
assert.equal(upstream.shorthand(), upstreamName);
6969
});
7070
});
71+
72+
it("can get the name of a branch", function() {
73+
var branch = this.branch;
74+
75+
return NodeGit.Branch.name(branch)
76+
.then(function(branchNameToTest) {
77+
assert.equal(branchNameToTest, branchName);
78+
});
79+
});
7180
});

0 commit comments

Comments
 (0)