Skip to content

Commit c843627

Browse files
committed
Duplicate the string out of the native abstraction class
As the class is scoped to the for loop it is destroyed which means that the memory for the string is cleared. This disallows any strings to be correctly converted into a git_strarray.
1 parent b4f0caf commit c843627

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(size_t 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)