Skip to content

Commit b080622

Browse files
committed
Merge pull request nodegit#451 from mattyclarkson/str-array-converter-fix
StrArrayConverter fix
2 parents d440ea1 + c843627 commit b080622

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

generate/templates/manual/src/str_array_converter.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ git_strarray *StrArrayConverter::Convert(Handle<v8::Value> val) {
2525
}
2626

2727
git_strarray *StrArrayConverter::ConvertArray(Array *val) {
28-
int count = val->Length();
29-
char **strings = (char **)malloc(sizeof(char*) * count);
30-
git_strarray *result;
28+
git_strarray *result = (git_strarray *)malloc(sizeof(git_strarray*));
29+
result->count = val->Length();
30+
result->strings = (char **)malloc(sizeof(char*) * result->count);
3131

32-
for(int i = 0; i < count; i++) {
32+
for(size_t i = 0; i < result->count; i++) {
3333
NanUtf8String entry(val->Get(i));
34-
strings[i] = *entry;
34+
result->strings[i] = strdup(*entry);
3535
}
3636

37-
result = ConstructStrArray(count, strings);
38-
free(strings);
3937
return result;
4038
}
4139

0 commit comments

Comments
 (0)